@noir-lang/noir_codegen 0.39.0 → 1.0.0-9c1fafc.nightly
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/lib/main.js +2 -2
- package/lib/utils/typings_generator.js +16 -6
- package/package.json +18 -19
package/lib/main.js
CHANGED
|
@@ -14,8 +14,8 @@ function main() {
|
|
|
14
14
|
const programs = files.map((file_path) => {
|
|
15
15
|
const program_name = path.parse(file_path).name;
|
|
16
16
|
const file_contents = fs.readFileSync(file_path).toString();
|
|
17
|
-
const { abi, bytecode } = JSON.parse(file_contents);
|
|
18
|
-
return [program_name, { abi, bytecode }];
|
|
17
|
+
const { abi, bytecode, debug_symbols, file_map } = JSON.parse(file_contents);
|
|
18
|
+
return [program_name, { abi, bytecode, debug_symbols, file_map }];
|
|
19
19
|
});
|
|
20
20
|
const result = codegen(programs, !cliConfig.externalArtifact, cliConfig.useFixedLengthArrays);
|
|
21
21
|
const outputDir = path.resolve(cliConfig.outDir ?? './codegen');
|
|
@@ -4,9 +4,9 @@ const codegenPrelude = `/* Autogenerated file, do not edit! */
|
|
|
4
4
|
|
|
5
5
|
/* eslint-disable */
|
|
6
6
|
|
|
7
|
-
import { Noir, InputMap, CompiledCircuit, ForeignCallHandler } from "@noir-lang/noir_js"
|
|
7
|
+
import { Noir, type InputMap, type CompiledCircuit, type ForeignCallHandler } from "@noir-lang/noir_js"
|
|
8
8
|
|
|
9
|
-
export { ForeignCallHandler } from "@noir-lang/noir_js"
|
|
9
|
+
export { type ForeignCallHandler } from "@noir-lang/noir_js"
|
|
10
10
|
`;
|
|
11
11
|
/**
|
|
12
12
|
* Returns the last component of a path, e.g. "foo::bar::baz" -\> "baz"
|
|
@@ -238,17 +238,27 @@ ${interfacesCode}`;
|
|
|
238
238
|
}
|
|
239
239
|
const codegenFunction = (name, function_signature, compiled_program) => {
|
|
240
240
|
const args = function_signature.inputs.map(([name]) => `${name}`).join(', ');
|
|
241
|
-
const args_with_types = function_signature.inputs.map(([name, type]) => `${name}: ${type}`)
|
|
241
|
+
const args_with_types = function_signature.inputs.map(([name, type]) => `${name}: ${type}`);
|
|
242
|
+
if (!compiled_program) {
|
|
243
|
+
args_with_types.push(`${name}_circuit: CompiledCircuit`);
|
|
244
|
+
}
|
|
245
|
+
args_with_types.push('foreignCallHandler?: ForeignCallHandler');
|
|
246
|
+
const args_with_types_joined_by_comma = args_with_types.join(', ');
|
|
242
247
|
const artifact = compiled_program
|
|
243
248
|
? `export const ${name}_circuit: CompiledCircuit = ${JSON.stringify(compiled_program)};`
|
|
244
249
|
: '';
|
|
250
|
+
const returnType = function_signature.returnValue;
|
|
251
|
+
const hasReturnValue = returnType != null;
|
|
252
|
+
const body = hasReturnValue
|
|
253
|
+
? ` const { returnValue } = await program.execute(args, foreignCallHandler);
|
|
254
|
+
return returnValue as ${returnType};`
|
|
255
|
+
: ` await program.execute(args, foreignCallHandler);`;
|
|
245
256
|
return `${artifact}
|
|
246
257
|
|
|
247
|
-
export async function ${name}(${
|
|
258
|
+
export async function ${name}(${args_with_types_joined_by_comma}): Promise<${hasReturnValue ? returnType : 'void'}> {
|
|
248
259
|
const program = new Noir(${name}_circuit);
|
|
249
260
|
const args: InputMap = { ${args} };
|
|
250
|
-
|
|
251
|
-
return returnValue as ${function_signature.returnValue};
|
|
261
|
+
${body}
|
|
252
262
|
}
|
|
253
263
|
`;
|
|
254
264
|
};
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"contributors": [
|
|
4
4
|
"The Noir Team <team@noir-lang.org>"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.
|
|
7
|
-
"packageManager": "yarn@
|
|
6
|
+
"version": "1.0.0-9c1fafc.nightly",
|
|
7
|
+
"packageManager": "yarn@4.5.2",
|
|
8
8
|
"license": "(MIT OR Apache-2.0)",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"homepage": "https://noir-lang.org/",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"url": "https://github.com/noir-lang/noir/issues"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@noir-lang/types": "0.
|
|
21
|
-
"glob": "^
|
|
20
|
+
"@noir-lang/types": "1.0.0-9c1fafc.nightly",
|
|
21
|
+
"glob": "^13.0.6",
|
|
22
22
|
"ts-command-line-args": "^2.5.1"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
@@ -35,29 +35,28 @@
|
|
|
35
35
|
"dev": "tsc-multi --watch",
|
|
36
36
|
"build": "tsc",
|
|
37
37
|
"test": "yarn test:codegen && yarn test:node && yarn test:clean",
|
|
38
|
-
"test:codegen": "nargo export --program-dir=./test/test_lib && tsx src/main.ts ./test/test_lib/export/** --out-dir ./test/codegen",
|
|
38
|
+
"test:codegen": "rm -rf ./test/test_lib/export && ${NARGO:-nargo} export --program-dir=./test/test_lib && tsx src/main.ts ./test/test_lib/export/** --out-dir ./test/codegen",
|
|
39
39
|
"test:node": "mocha --timeout 25000 --exit --config ./.mocharc.json",
|
|
40
40
|
"test:clean": "rm -rf ./test/codegen ./test/test_lib/export",
|
|
41
41
|
"prettier": "prettier 'src/**/*.ts'",
|
|
42
42
|
"prettier:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
|
|
43
|
-
"lint": "NODE_NO_WARNINGS=1 eslint . --
|
|
43
|
+
"lint": "NODE_NO_WARNINGS=1 eslint . --max-warnings 0",
|
|
44
44
|
"nightly:version": "jq --arg new_version \"-$(git rev-parse --short HEAD)$1\" '.version = .version + $new_version' package.json > package-tmp.json && mv package-tmp.json package.json",
|
|
45
45
|
"publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish",
|
|
46
46
|
"clean": "rm -rf ./lib"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@noir-lang/noir_js": "0.
|
|
50
|
-
"@types/chai": "^
|
|
51
|
-
"@types/mocha": "^10.0.
|
|
52
|
-
"@types/node": "^20.
|
|
53
|
-
"@types/prettier": "^3",
|
|
54
|
-
"chai": "^
|
|
55
|
-
"eslint": "^
|
|
56
|
-
"eslint-plugin-prettier": "^5.
|
|
57
|
-
"mocha": "^
|
|
58
|
-
"prettier": "3.
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"typescript": "^5.4.2"
|
|
49
|
+
"@noir-lang/noir_js": "1.0.0-9c1fafc.nightly",
|
|
50
|
+
"@types/chai": "^5",
|
|
51
|
+
"@types/mocha": "^10.0.10",
|
|
52
|
+
"@types/node": "^22.20.5",
|
|
53
|
+
"@types/prettier": "^3.0.0",
|
|
54
|
+
"chai": "^6.3.0",
|
|
55
|
+
"eslint": "^10.13.0",
|
|
56
|
+
"eslint-plugin-prettier": "^5.5.7",
|
|
57
|
+
"mocha": "^12.0.3",
|
|
58
|
+
"prettier": "3.9.10",
|
|
59
|
+
"tsx": "^4.23.15",
|
|
60
|
+
"typescript": "^6.0.3"
|
|
62
61
|
}
|
|
63
62
|
}
|