Skip to content

Commit e12dc77

Browse files
committed
verify:circom-multi command
1 parent 059e5ea commit e12dc77

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

cli.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import {Command} from 'commander';
33

4-
import {verify, deploy} from './index.js';
4+
import {verify, deploy, verifyMulti} from './index.js';
55
import {
66
instanceSizes,
77
getPackageJson,
@@ -46,4 +46,10 @@ program
4646
.option('-b, --browser-wallet', 'Send transaction in browser instead of by passing private key env var (overrides chainId argument)')
4747
.action(deploy);
4848

49+
program
50+
.command('verify:circom-multi <jsonFile>')
51+
.description('Verify a Groth16 multi-verifier using a JSON specification. See docs website for details.')
52+
.option('-c, --config <configUrl>', `Specify a different configuration file (default: ${DEFAULT_CONFIG})`)
53+
.action(verifyMulti);
54+
4955
program.parse(process.argv);

index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {relative, dirname} from 'node:path';
2+
import {readFileSync} from 'node:fs';
23

34
import { isHex } from 'viem';
45
import * as chains from 'viem/chains';
@@ -83,6 +84,41 @@ export async function deploy(file, chainId, options) {
8384
process.exit(0);
8485
}
8586

87+
export async function verifyMulti(file, options) {
88+
options = await loadConfig(options);
89+
const parsed = JSON.parse(readFileSync(file, 'utf8'));
90+
const event = {
91+
payload: {
92+
...parsed,
93+
action: 'verifyCircomMulti',
94+
},
95+
};
96+
console.log(`# Verifying groth16 multi-verifier...`);
97+
98+
const response = await fetch(options.config.serverURL, {
99+
method: 'POST',
100+
headers: {
101+
'Content-Type': 'application/json',
102+
},
103+
body: JSON.stringify(event),
104+
});
105+
if (!response.ok && response.status !== 400) {
106+
throw new Error('Network response was not ok');
107+
}
108+
const data = await response.json();
109+
const body = 'body' in data ? JSON.parse(data.body) : data;
110+
if('errorType' in body) {
111+
throw new Error(`Verification error: ${body.errorMessage}`);
112+
}
113+
114+
if(body && body.status === 'verified') {
115+
console.log(`# Completed successfully!`);
116+
console.log(`\nhttps://circuitscan.org/chain/${parsed.deployed.chainId}/address/${parsed.deployed.address}`);
117+
} else {
118+
console.log(`# Verification failed.`);
119+
}
120+
}
121+
86122
function viemChain(nameOrId) {
87123
if(isNaN(nameOrId)) {
88124
return chains[nameOrId];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "circuitscan",
3-
"version": "0.0.23-alpha",
3+
"version": "0.0.24-alpha",
44
"main": "index.js",
55
"type": "module",
66
"author": "numtel <[email protected]>",

0 commit comments

Comments
 (0)