parent
c72e6caaf6
commit
370c38bc60
@ -0,0 +1,15 @@ |
||||
export const sindriScripts = async (plugin) => { |
||||
await plugin.call('fileManager', 'writeFile',
|
||||
'scripts/sindri/sindri.ts' , |
||||
// @ts-ignore
|
||||
(await import('!!raw-loader!./sindri.ts')).default) |
||||
|
||||
|
||||
await plugin.call('fileManager', 'writeFile',
|
||||
'sindri.json' , |
||||
// @ts-ignore
|
||||
(await import('raw-loader!./sindri.conf')).default) |
||||
|
||||
|
||||
await plugin.call('fileManager', 'open', 'scripts/sindri/sindri.ts') |
||||
} |
@ -0,0 +1,8 @@ |
||||
{ |
||||
"$schema": "https://forge.sindri.app/api/v1/sindri-manifest-schema.json", |
||||
"name": "circuit name", |
||||
"circuitType": "circom", |
||||
"curve": "bn254", |
||||
"provingScheme": "groth16", |
||||
"witnessCompiler": "c++" |
||||
} |
@ -0,0 +1,58 @@ |
||||
import client from 'sindri' |
||||
|
||||
/** |
||||
* Compile the given circuit |
||||
* @param {string} entryPoint - path to the circuit to compile |
||||
* @param {string} apiKey - sindri API key |
||||
* @returns {Circuit} compiled circuit |
||||
*/ |
||||
export const createCircuit = async (entryPoint: string, apiKey: string) => { |
||||
client.authorize({ apiKey }) |
||||
|
||||
const sindriConf = await remix.call('fileManager', 'readFile', `sindri.json`) |
||||
const circuit = await remix.call('fileManager', 'readFile', entryPoint) |
||||
const deps = await remix.call('circuit-compiler' as any, 'resolveDependencies', entryPoint, circuit) |
||||
|
||||
const files = [] |
||||
files.push(new File([circuit], 'circuit.circom')) |
||||
files.push(new File([sindriConf], 'sindri.json'))
|
||||
|
||||
for (const file in deps) { |
||||
if (file === entryPoint) continue |
||||
files.push(new File([deps[file]], file)) |
||||
} |
||||
|
||||
const circuitProject = await client.createCircuit(files) |
||||
return circuitProject |
||||
} |
||||
|
||||
/** |
||||
* Generate a proof against the given circuit |
||||
* @param {string} circuitId - id of the circuit |
||||
* @param {Object} signals - input signals |
||||
* @returns {Proof} generated proof |
||||
*/ |
||||
export const proveCircuit = async (circuitId: string, signals: { [id: string]: string }, apiKey: string) => { |
||||
client.authorize({ apiKey }) |
||||
const proof = await client.proveCircuit(circuitId, JSON.stringify(signals)) |
||||
return proof |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Save the circuit
|
||||
* @param {Circuit} circuitProject - compiled circuit |
||||
*/ |
||||
export const saveCircuit = async (circuitProject) => { |
||||
await remix.call('fileManager', 'writeFile', `.sindri/${circuitProject.circuit_id}.json`, JSON.stringify(circuitProject, null, '\t'))
|
||||
} |
||||
|
||||
/** |
||||
* Load the circuit
|
||||
* @param {string} circuitId - id of the circuit |
||||
* @param {Object} signals - input signals |
||||
* @returns {Proof} generated proof |
||||
*/ |
||||
export const loadCircuit = async (circuitId: string) => { |
||||
return JSON.parse(await remix.call('fileManager', 'readFile', `.sindri/${circuitId}.json`)) |
||||
} |
Loading…
Reference in new issue