Last active
September 19, 2023 09:44
-
-
Save yann300/e39911dfba7d87802dfeed8bb8ebf500 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const api_key = "qmZtKNT5swfCkkHVoZZ8N2HKv656jFXx" | |
const API_VERSION = "v1" | |
const API_URL = `https://forge.sindri.app/api/${API_VERSION}/` | |
const api_key_querystring = `?api_key=${api_key}` | |
const headers_json = {"Accept": "application/json"} | |
const headers_multipart = {"Accept": "multipart/form-data"} | |
const headers_urlencode = { | |
"Accept": "application/json", | |
"Content-Type": "application/x-www-form-urlencoded", | |
}; | |
(async () => { | |
try { | |
console.log("1. Creating circuit...") | |
const createJson = {"circuit_name": "multiplier_example", "circuit_type": "Circom C Groth16 bn254"} | |
let response = await fetch(API_URL + "circuit/create" + api_key_querystring, { method: 'POST', headers: headers_json, body: JSON.stringify(createJson) }) | |
const circuitId = (await response.json())['circuit_id'] | |
console.log('circuit id', circuitId) | |
console.log("2. Uploading Files...") | |
const circuit = await remix.call('fileManager', 'readFile', './circom/multiplier2/circuit.circom') | |
response = await fetch(API_URL + `circuit/${circuitId}/uploadfiles` + api_key_querystring, { method: 'POST', headers: headers_multipart, body: circuit }) | |
console.log("3. Compile...") | |
await fetch(`circuit/${circuitId}/compile` + api_key_querystring, { method: 'POST', headers: headers_json }) | |
await (new Promise((resolve) => setTimeout(() => resolve({}), 10000))) | |
response = await fetch(API_URL + `circuit/${circuitId}/detail` + api_key_querystring, { method: 'GET', headers: headers_json }) | |
response = await response.json() | |
console.log(response) | |
console.log("4. Proving circuit...") | |
const inputs = {"a": "7", "b": "42"} | |
response = await fetch(API_URL + `circuit/${circuitId}/prove` + api_key_querystring, { method: 'POST', headers: headers_urlencode, body: JSON.stringify(inputs)}) | |
response = await response.json() | |
const proofId = (await response.json())['proof_id'] | |
console.log('proof id', proofId) | |
await (new Promise((resolve) => setTimeout(() => resolve({}), 10000))) | |
const params = { | |
"include_proof_input": false, | |
"include_public": true, | |
"include_verification_key": false, | |
"include_proof": false, | |
} | |
response = await fetch(API_URL + `proof/${proofId}/detail` + api_key_querystring, { method: 'GET', headers: headers_json, body: JSON.stringify(params) }) | |
response = await response.json() | |
console.log(response) | |
} catch (e) { | |
console.error(e.message) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment