Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Generate declaration files for VKs #7391

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,22 @@ async function readVKFromS3(artifactName, artifactHash) {
if (process.env.DISABLE_VK_S3_CACHE) {
return;
}
const key = `${PREFIX}/${artifactName}-${artifactHash}.json`;

try {
const s3 = generateS3Client();
const { Body: response } = await s3.getObject({
Bucket: BUCKET_NAME,
Key: `${PREFIX}/${artifactName}-${artifactHash}.json`,
Key: key,
});

const result = JSON.parse(await response.transformToString());
return result;
} catch (err) {
console.warn("Could not read VK from remote cache", err.message);
console.warn(
`Could not read VK from remote cache at s3://${BUCKET_NAME}/${key}`,
err.message
);
return undefined;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ import { fileURLToPath } from '@aztec/foundation/url';
import { readdir, writeFile } from 'fs/promises';
import { join } from 'path';

const content = `\
const contract = `\
import { type NoirCompiledCircuit } from '@aztec/types/noir';
const circuit: NoirCompiledCircuit;
export = circuit;
`;

const target = fileURLToPath(new URL('../../artifacts', import.meta.url).href);
const files = await readdir(target);
for (const file of files) {
// guard against running this script twice without cleaning the artifacts/ dir first
if (!file.endsWith('.json')) {
continue;
const vk = `\
const vk: { keyAsBytes: string; keyAsFields: string[] };
export = vk;
`;

async function generateDeclarationFor(target: string, content: string) {
const files = await readdir(target);
for (const file of files) {
// guard against running this script twice without cleaning the artifacts/ dir first
if (!file.endsWith('.json')) {
continue;
}
const name = file.replace('.json', '');
await writeFile(join(target, `${name}.d.json.ts`), content);
}
const name = file.replace('.json', '');
await writeFile(join(target, `${name}.d.json.ts`), content);
}

// Generate declaration files for contracts
await generateDeclarationFor(fileURLToPath(new URL('../../artifacts', import.meta.url).href), contract);

// Generate declaration files for vks
await generateDeclarationFor(fileURLToPath(new URL('../../artifacts/keys', import.meta.url).href), vk);
2 changes: 1 addition & 1 deletion yarn-project/noir-protocol-circuits-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
"path": "../merkle-tree"
}
],
"include": ["src", "artifacts/*.d.json.ts"]
"include": ["src", "artifacts/*.d.json.ts", "artifacts/**/*.d.json.ts", ]
}
Loading