|
|
@ -46,33 +46,31 @@ export const sindriScripts = async (plugin: any) => { |
|
|
|
// For now, we only support Circom.
|
|
|
|
// For now, we only support Circom.
|
|
|
|
|
|
|
|
|
|
|
|
// Infer manifest properties from the existing files in the workspace.
|
|
|
|
// Infer manifest properties from the existing files in the workspace.
|
|
|
|
switch (sindriManifest.circuitType) { |
|
|
|
if (sindriManifest.circuitType === 'circom') { |
|
|
|
case 'circom': |
|
|
|
// Try to find the best `.circom` source file to use as the main component.
|
|
|
|
// Try to find the best `.circom` source file to use as the main component.
|
|
|
|
// First, we limit ourselves to `.circom` files.
|
|
|
|
// First, we limit ourselves to `.circom` files.
|
|
|
|
const circomPathsAndContents = await Promise.all( |
|
|
|
const circomPathsAndContents = await Promise.all( |
|
|
|
Object.entries(existingFilesByPath) |
|
|
|
Object.entries(existingFilesByPath) |
|
|
|
.filter(([path]) => /\.circom$/i.test(path)) |
|
|
|
.filter(([path]) => /\.circom$/i.test(path)) |
|
|
|
.map(async ([path, file]) => [path, await file.text()]) |
|
|
|
.map(async ([path, file]) => [path, await file.text()]) |
|
|
|
) |
|
|
|
) |
|
|
|
// Now we apply some heuristics to find the "best" file.
|
|
|
|
// Now we apply some heuristics to find the "best" file.
|
|
|
|
const circomCircuitPath = |
|
|
|
const circomCircuitPath = |
|
|
|
circomPathsAndContents |
|
|
|
circomPathsAndContents |
|
|
|
.map(([path, content]) => ({ |
|
|
|
.map(([path, content]) => ({ |
|
|
|
content, |
|
|
|
content, |
|
|
|
hasMainComponent: !!/^[ \t\f]*component[ \t\f]+main[^\n\r]*;[ \t\f]*$/m.test(content), |
|
|
|
hasMainComponent: !!/^[ \t\f]*component[ \t\f]+main[^\n\r]*;[ \t\f]*$/m.test(content), |
|
|
|
// These files are the entrypoints to the Remix Circom templates, so we give them a boost if there are multiple main components.
|
|
|
|
// These files are the entrypoints to the Remix Circom templates, so we give them a boost if there are multiple main components.
|
|
|
|
isTemplateEntrypoint: !!['calculate_hash.circom', 'rln.circom', 'semaphore.circom'].includes(path.split('/').pop() ?? ''), |
|
|
|
isTemplateEntrypoint: !!['calculate_hash.circom', 'rln.circom', 'semaphore.circom'].includes(path.split('/').pop() ?? ''), |
|
|
|
path, |
|
|
|
path, |
|
|
|
})) |
|
|
|
})) |
|
|
|
.sort((a, b) => { |
|
|
|
.sort((a, b) => { |
|
|
|
if (a.hasMainComponent !== b.hasMainComponent) return +b.hasMainComponent - +a.hasMainComponent |
|
|
|
if (a.hasMainComponent !== b.hasMainComponent) return +b.hasMainComponent - +a.hasMainComponent |
|
|
|
if (a.isTemplateEntrypoint !== b.isTemplateEntrypoint) return +b.isTemplateEntrypoint - +a.isTemplateEntrypoint |
|
|
|
if (a.isTemplateEntrypoint !== b.isTemplateEntrypoint) return +b.isTemplateEntrypoint - +a.isTemplateEntrypoint |
|
|
|
return a.path.localeCompare(b.path) |
|
|
|
return a.path.localeCompare(b.path) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.map(({path}) => path)[0] || './circuit.circom' |
|
|
|
.map(({path}) => path)[0] || './circuit.circom' |
|
|
|
sindriManifest.circuitPath = circomCircuitPath |
|
|
|
sindriManifest.circuitPath = circomCircuitPath |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Derive the circuit name from the workspace name.
|
|
|
|
// Derive the circuit name from the workspace name.
|
|
|
|