From 504683c067eae2691102d95ed31820716e5e43ef Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 24 May 2024 10:24:09 +0200 Subject: [PATCH] Add verifierData.ts --- .../oracles/src/noir/circuit/verifierData.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ethereum/oracles/src/noir/circuit/verifierData.ts diff --git a/ethereum/oracles/src/noir/circuit/verifierData.ts b/ethereum/oracles/src/noir/circuit/verifierData.ts new file mode 100644 index 00000000..7fd8317d --- /dev/null +++ b/ethereum/oracles/src/noir/circuit/verifierData.ts @@ -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(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 + ) {} +}