@nori-zk/o1js-zk-utils
Version:
o1js-zk-utils supporting Nori Bridge
94 lines (93 loc) • 4.49 kB
TypeScript
import { Bool, type Cache, Field, type SmartContract, UInt64, type UInt8, type VerificationKey } from 'o1js';
import { type NoriSP1ProofInput } from '@nori-zk/pts-types';
import { type CompilableZkProgram, type CreateProofArgument } from './types.js';
import { type Logger } from 'esm-iso-logger';
export declare function isLessThanFieldPrimeLE(bytes: UInt8[]): Bool;
export declare function bytes32LEToFieldProvable(uint8ArrayLength32: UInt8[]): import("o1js/dist/node/lib/provable/field.js").Field;
export declare function uint8ArrayToBigIntBE(bytes: Uint8Array): bigint;
export declare function uint8ArrayToBigIntLE(bytes: Uint8Array): bigint;
export declare function fieldToHexBE(field: Field): string;
export declare function fieldToBigIntBE(field: Field): bigint;
export declare function fieldToHexLE(field: Field): string;
export declare function fieldToBigIntLE(field: Field): bigint;
export declare function decodeConsensusMptProof(ethSP1Proof: NoriSP1ProofInput): {
inputSlot: UInt64;
inputStoreHash: import("o1js/dist/node/lib/provable/bytes.js").Bytes;
outputSlot: UInt64;
outputStoreHash: import("o1js/dist/node/lib/provable/bytes.js").Bytes;
executionStateRoot: import("o1js/dist/node/lib/provable/bytes.js").Bytes;
verifiedContractDepositsRoot: import("o1js/dist/node/lib/provable/bytes.js").Bytes;
nextSyncCommitteeHash: import("o1js/dist/node/lib/provable/bytes.js").Bytes;
contractAddress: import("o1js/dist/node/lib/provable/bytes.js").Bytes;
genesisRoot: import("o1js/dist/node/lib/provable/bytes.js").Bytes;
};
export declare function extractEthTokenBridgeAddressFromSP1Proof(example: CreateProofArgument): Field;
export declare function extractGenesisRootFromSP1Proof(example: CreateProofArgument): Field;
export declare function compileAndVerifyContracts(logger: Logger, contracts: {
name: string;
program: typeof SmartContract | CompilableZkProgram;
integrityHash: string;
}[]): Promise<Record<string, {
data: string;
hash: Field;
}>>;
export type VerificationKeySafe = {
hashStr: string;
data: string;
};
export declare function vkToVkSafe(vk: VerificationKey): VerificationKeySafe;
export declare function vkSafeToVk(vkSafe: VerificationKeySafe): VerificationKey;
/**
* Compiles a list of SmartContracts or CompilableZkPrograms and optionally verifies their
* verification key hashes against provided integrity hashes.
*
* @template T - An array of contract descriptors. Each descriptor must include:
* - `name`: The contract/program name (used as a key for the returned verification key).
* - `program`: Either a `SmartContract` class or a `CompilableZkProgram`.
* - `integrityHash` (optional): The expected verification key hash to validate against.
*
* @param logger - Logger object with a `.log(string)` method for outputting progress messages.
* Type: `{ log: (msg: string) => void }`.
* @param contracts - Array of contract/program descriptors to compile and optionally verify.
* @param cacheConfig - Optional cache configuration (`FileSystem` or `Network`) to use during compilation.
*
* @returns A Promise resolving to an object mapping each contract name to its `VerificationKey`.
* Keys are of the form `${name}VerificationKey`.
*
* @throws Will throw an Error if any computed verification key hash does not match
* its expected `integrityHash`, including a helpful message on clearing the cache
* or regenerating verification keys.
*
* Example usage:
* ```ts
* const vks = await compileAndOptionallyVerifyContracts(
* { log: console.log },
* [
* { name: 'MyContract', program: MyContract, integrityHash: '12345' },
* { name: 'MyProgram', program: MyZkProgram },
* ],
* cacheConfig
* );
* ```
*/
export declare function compileAndOptionallyVerifyContracts<T extends readonly {
name: string;
program: typeof SmartContract | CompilableZkProgram;
integrityHash?: string;
}[]>(logger: {
log: (msg: string) => void;
}, contracts: T, cache?: Cache): Promise<{
[K in T[number]['name'] as `${K}VerificationKey`]: VerificationKey;
}>;
export type ZKCache = {
name: string;
integrityHash?: string;
};
export type ZKCacheWithProgram = ZKCache & {
program: typeof SmartContract | CompilableZkProgram;
};
export type ZKCacheLayout = ZKCache & {
files: string[];
};
export declare function createTimer(): () => string;
export declare function formatDuration(ms: number): string;