Arrays
Arrays in provable code must be of a fixed size. Normal JavaScript arrays are a suitable value to pass into a provable function, but
Array<T>
is not a suitable type. o1js exports the Provable.Array
helper to generate provable array classes.
const FieldArray3 = Provable.Array(Field, 3);
const SignatureArray2 = Provable.Array(Signature, 2);
JavaScript arrays will satisfy the provable array type as long as they are of the correct size, so you don't need to worry too much about casting them back and forth.
const fieldArray = Provable.witness(FieldArray3, () => {
return [Field(1), Field(2), Field(3)];
});
fieldArray.map((x) => x.toBigInt()); // [1n, 2n, 3n]
Read more at the language reference: Provable.Array.