diff --git a/ethereum/oracles/src/noir/oracles/oracles.test.ts b/ethereum/oracles/src/noir/oracles/oracles.test.ts deleted file mode 100644 index 6ca18978d..000000000 --- a/ethereum/oracles/src/noir/oracles/oracles.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import { createOracles } from './oracles.js'; -import { MultiChainClient } from '../../ethereum/client.js'; - -describe('importOracles', () => { - it('success', async () => { - const oracle = createOracles({} as MultiChainClient)({ - stub: async () => await Promise.resolve(['7']) - }); - expect(await oracle('stub', [])).toStrictEqual(['7']); - }); - - it('throws when non-existing oracle', async () => { - const oracle = createOracles({} as MultiChainClient)({}); - await expect(oracle('non-existing', [])).rejects.toThrow(); - }); -}); diff --git a/ethereum/oracles/src/noir/oracles/oracles.ts b/ethereum/oracles/src/noir/oracles/oracles.ts deleted file mode 100644 index b451cfad7..000000000 --- a/ethereum/oracles/src/noir/oracles/oracles.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { type ForeignCallOutput } from '@noir-lang/noir_js'; -import { MultiChainClient } from '../../ethereum/client.js'; -import { getAccountOracle } from './rpc/accountOracle.js'; -import { getHeaderOracle } from './rpc/headerOracle.js'; -import { getProofOracle } from './rpc/proofOracle.js'; -import { getReceiptOracle } from './rpc/receiptOracle.js'; -import { getTransactionOracle } from './rpc/transactionOracle.js'; - -export type NoirArgument = string[]; -export type NoirArguments = NoirArgument[]; - -export type Oracle = (multiChainClient: MultiChainClient, args: NoirArguments) => Promise<ForeignCallOutput[]>; - -export type Oracles = (name: string, args: NoirArguments) => Promise<ForeignCallOutput[]>; - -type OracleMap = Record<string, Oracle>; - -export const createOracles = - (multiChainClient: MultiChainClient) => - (dict: OracleMap): Oracles => - async (name: string, args: NoirArguments): Promise<ForeignCallOutput[]> => { - const fn = dict[name]; - if (fn === undefined) { - throw new Error(`Unknown oracle ${name}`); - } - return await fn(multiChainClient, args); - }; - -export const defaultOraclesMap: OracleMap = { - get_account: getAccountOracle, - get_header: getHeaderOracle, - get_proof: getProofOracle, - get_receipt: getReceiptOracle, - get_transaction: getTransactionOracle -}; diff --git a/ethereum/oracles/src/noir/oracles/rpc/accountOracle.ts b/ethereum/oracles/src/noir/oracles/rpc/accountOracle.ts index d4dc42e55..9bb434dd5 100644 --- a/ethereum/oracles/src/noir/oracles/rpc/accountOracle.ts +++ b/ethereum/oracles/src/noir/oracles/rpc/accountOracle.ts @@ -3,7 +3,7 @@ import { type Address } from 'viem'; import { assert } from '../../../util/assert.js'; import { encodeAccount, encodeStateProof } from './accountOracle/encode.js'; import { decodeAddress, decodeField } from '../common/decode.js'; -import { NoirArguments } from '../oracles.js'; +import { NoirArguments } from '../types.js'; import { MultiChainClient } from '../../../ethereum/client.js'; import { Enum } from '../../../util/enum.js'; diff --git a/ethereum/oracles/src/noir/oracles/rpc/headerOracle.ts b/ethereum/oracles/src/noir/oracles/rpc/headerOracle.ts index ee490ae59..39ebb1936 100644 --- a/ethereum/oracles/src/noir/oracles/rpc/headerOracle.ts +++ b/ethereum/oracles/src/noir/oracles/rpc/headerOracle.ts @@ -3,7 +3,7 @@ import { type BlockHeader, blockToHeader } from '../../../ethereum/blockHeader.j import { assert } from '../../../util/assert.js'; import { encodeBlockHeader } from './headerOracle/encode.js'; import { decodeField } from '../common/decode.js'; -import { NoirArguments } from '../oracles.js'; +import { NoirArguments } from '../types.js'; import { type Block } from '../../../ethereum/blockHeader.js'; import { AlchemyClient, MultiChainClient } from '../../../ethereum/client.js'; import { Enum } from '../../../util/enum.js'; diff --git a/ethereum/oracles/src/noir/oracles/rpc/proofOracle.ts b/ethereum/oracles/src/noir/oracles/rpc/proofOracle.ts index 72c60359a..c2d30f214 100644 --- a/ethereum/oracles/src/noir/oracles/rpc/proofOracle.ts +++ b/ethereum/oracles/src/noir/oracles/rpc/proofOracle.ts @@ -2,7 +2,7 @@ import { type ForeignCallOutput } from '@noir-lang/noir_js'; import { assert } from '../../../util/assert.js'; import { encodeAccount, encodeStateProof, encodeStorageProof } from './accountOracle/encode.js'; import { decodeAddress, decodeBytes32, decodeField } from '../common/decode.js'; -import { NoirArguments } from '../oracles.js'; +import { NoirArguments } from '../types.js'; import { Hex } from 'viem'; import { MultiChainClient } from '../../../ethereum/client.js'; import { Enum } from '../../../util/enum.js'; diff --git a/ethereum/oracles/src/noir/oracles/rpc/receiptOracle.ts b/ethereum/oracles/src/noir/oracles/rpc/receiptOracle.ts index 989f098b3..a746e5c4c 100644 --- a/ethereum/oracles/src/noir/oracles/rpc/receiptOracle.ts +++ b/ethereum/oracles/src/noir/oracles/rpc/receiptOracle.ts @@ -1,7 +1,7 @@ import { type ForeignCallOutput } from '@noir-lang/noir_js'; import { assert } from '../../../util/assert.js'; import { decodeField } from '../common/decode.js'; -import { NoirArguments } from '../oracles.js'; +import { NoirArguments } from '../types.js'; import { MultiChainClient } from '../../../ethereum/client.js'; import { getReceiptProof } from '../../../ethereum/receiptProof.js'; import { encodeReceipt, encodeReceiptProof } from './receiptOracle/encode.js'; diff --git a/ethereum/oracles/src/noir/oracles/rpc/transactionOracle.ts b/ethereum/oracles/src/noir/oracles/rpc/transactionOracle.ts index 9133e277c..cca2428d9 100644 --- a/ethereum/oracles/src/noir/oracles/rpc/transactionOracle.ts +++ b/ethereum/oracles/src/noir/oracles/rpc/transactionOracle.ts @@ -1,5 +1,5 @@ import { type ForeignCallOutput } from '@noir-lang/noir_js'; -import { NoirArguments } from '../oracles.js'; +import { NoirArguments } from '../types.js'; import { MultiChainClient } from '../../../ethereum/client.js'; import { txTypeToHex } from '../../../ethereum/receipt.js'; import { getTxProof } from '../../../ethereum/txProof.js'; diff --git a/ethereum/oracles/src/noir/oracles/server/encode.test.ts b/ethereum/oracles/src/noir/oracles/server/encode.test.ts index b85c97f85..6a2056cf8 100644 --- a/ethereum/oracles/src/noir/oracles/server/encode.test.ts +++ b/ethereum/oracles/src/noir/oracles/server/encode.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect } from 'vitest'; import { decodeNoirArguments, encodeForeignCallResult } from './encode.js'; import { ForeignCallParams, ForeignCallResult } from './types.js'; -import { NoirArguments } from '../oracles.js'; +import { NoirArguments } from '../types.js'; describe('decodeNoirArguments', () => { it('should decode a single foreign call param correctly', () => { diff --git a/ethereum/oracles/src/noir/oracles/server/encode.ts b/ethereum/oracles/src/noir/oracles/server/encode.ts index d6570d762..d383d610c 100644 --- a/ethereum/oracles/src/noir/oracles/server/encode.ts +++ b/ethereum/oracles/src/noir/oracles/server/encode.ts @@ -1,6 +1,6 @@ import { ForeignCallOutput } from '@noir-lang/noir_js'; import { ForeignCallParam, ForeignCallParams, ForeignCallResult } from './types.js'; -import { NoirArguments } from '../oracles.js'; +import { NoirArguments } from '../types.js'; /// DECODE export function decodeNoirArguments(params: ForeignCallParams): NoirArguments { diff --git a/ethereum/oracles/src/noir/oracles/server/handlers.ts b/ethereum/oracles/src/noir/oracles/server/handlers.ts index 007ab4066..68ba4879a 100644 --- a/ethereum/oracles/src/noir/oracles/server/handlers.ts +++ b/ethereum/oracles/src/noir/oracles/server/handlers.ts @@ -1,7 +1,7 @@ import { ForeignCallResult, ForeignCallParams } from './types.js'; import { decodeNoirArguments, encodeForeignCallResult } from './encode.js'; import { MultiChainClient } from '../../../ethereum/client.js'; -import { Oracle } from '../oracles.js'; +import { Oracle } from '../types.js'; /** * The format that the Noir oracles server receives the arguments in is slightly different than the format that acvm.js uses. diff --git a/ethereum/oracles/src/noir/oracles/types.ts b/ethereum/oracles/src/noir/oracles/types.ts new file mode 100644 index 000000000..857388c96 --- /dev/null +++ b/ethereum/oracles/src/noir/oracles/types.ts @@ -0,0 +1,7 @@ +import { type ForeignCallOutput } from '@noir-lang/noir_js'; +import { MultiChainClient } from '../../ethereum/client.js'; + +export type NoirArgument = string[]; +export type NoirArguments = NoirArgument[]; + +export type Oracle = (multiChainClient: MultiChainClient, args: NoirArguments) => Promise<ForeignCallOutput[]>;