Skip to content

Commit

Permalink
Add verifierData.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
LogvinovLeon committed May 28, 2024
1 parent 19cfead commit 504683c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ethereum/oracles/src/noir/circuit/verifierData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Abi, InputMap, abiEncode } from '@noir-lang/noirc_abi';
import { readTomlObject } from '../../util/file.js';
import { Hex } from 'viem';
import { CircuitAbi } from './abi.js';

export class VerifierData {
public static async create(verifierTomlPath: string, abi: Abi) {
const verifierData = await readTomlObject<InputMap>(verifierTomlPath);
return new VerifierData(new CircuitAbi(abi), verifierData);
}

public publicInputs(): Hex[] {
return this.encodeSubset(this.abi.public());
}

public returnValues(): Hex[] {
return this.encodeSubset(this.abi.return());
}

public encodeSubset(subset: Abi): Hex[] {
const subsetEncodedMap = abiEncode(subset, this.verifierData, this.verifierData.return);
return Array.from(subsetEncodedMap.values()) as Hex[];
}

private constructor(
private abi: CircuitAbi,
private verifierData: InputMap
) {}
}

0 comments on commit 504683c

Please sign in to comment.