import { Bool, Field, type InferProvable, Option, Provable, UInt32, type InferValue, type From, type ProvablePure, type IsPure } from 'o1js'; import { type ProvableHashableWide, ProvableType } from '../o1js-missing.ts'; export { StaticArray }; type StaticArray = StaticArrayBase; type StaticArrayClass = typeof StaticArrayBase & { provable: ProvableHashableWide, V[], (T | From)[]>; /** * Create a new StaticArray from an array of values. */ from(v: (T | From)[] | StaticArrayBase): StaticArrayBase; }; type StaticArrayClassPure = typeof StaticArrayBase & Omit, 'provable'> & { provable: ProvableHashableWide, V[], (T | From)[]> & Omit, V[]>, 'fromValue'>; }; /** * Array with a fixed number of elements and several helper methods. * * ```ts * const Bytes32 = StaticArray(UInt8, 32); * ``` * * The second parameter is the `length`. It can be any number from 0 to 2^16-1. */ declare function StaticArray = InferProvable, V extends InferValue = InferValue>(type: A, length: number): IsPure extends true ? StaticArrayClassPure : StaticArrayClass; declare namespace StaticArray { var from: (type: A, array: From[]) => StaticArrayBase, InferValue>; var Base: typeof StaticArrayBase; } declare class StaticArrayBase { /** * The plain array */ array: T[]; get innerType(): Provable; static get length(): number; get length(): number; /** * The `length` of the array. For compatibility with `DynamicArray`, we also provide it under `maxLength`. */ get maxLength(): number; constructor(array: T[]); [Symbol.iterator](): Generator; /** * Asserts that 0 <= i < this.length, using a cached check that's not duplicated when doing it on the same variable multiple times. * * Handles constants without creating constraints. * * Cost: 1.5 */ assertIndexInRange(i: UInt32 | number): void; /** * Gets value at index i, and proves that the index is in the array. * * Handles constant indices without creating constraints. * * Cost: TN + 1.5 */ get(i: UInt32 | number): T; /** * Gets a value at index i, as an option that is None if the index is not in the array. * * Note: The correct type for `i` is actually UInt16 which doesn't exist. The method is not complete (but sound) for i >= 2^16. * * Cost: TN + 2.5 */ getOption(i: UInt32 | number): Option; /** * Gets a value at index i, ASSUMING that the index is in the array. * * If the index is in fact not in the array, the return value is completely unconstrained. * * **Warning**: Only use this if you already know/proved by other means that the index is within bounds. * * Cost: T*N where T = size of the type */ getOrUnconstrained(i: Field): T; /** * Sets a value at index i and proves that the index is in the array. * * Cost: 1.5(T + 1)N + 1.5 */ set(i: UInt32 | number, value: T): void; /** * Sets a value at index i, or does nothing if the index is not in the array * * Cost: 1.5(T + 1)N */ setOrDoNothing(i: Field, value: T): void; /** * Map every element of the array to a new value. */ map(type: ProvableType, f: (t: T, i: number) => S): StaticArray; /** * Iterate over all elements of the array. */ forEach(f: (t: T, i: number) => void): void; /** * Reduce the array to a single value. */ reduce(state: S, f: (state: S, t: T) => S): S; /** * Split into a static number of fixed-size chunks. * Requires that the length is a multiple of the chunk size. */ chunk(chunkSize: number): StaticArrayBase, V[]>; /** * Reverse the array. * * Returns a copy and does not modify the original array. */ toReversed(): StaticArrayBase; slice(start: number, end: number): StaticArrayBase; _indexMasks: Map; _indicesInRange: Set; /** * Compute i.equals(j) for all indices j in the static-size array. * * Costs: 1.5N * * TODO: equals() could be optimized to just 1 double generic because j is constant, o1js doesn't do that */ _indexMask(i: Field): import("node_modules/o1js/dist/node/lib/provable/bool.js").Bool[]; toValue(): V[]; }