Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update array handling in Provable.toFields #285

Merged
merged 10 commits into from
Aug 21, 2024
11 changes: 10 additions & 1 deletion lib/provable-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ function createDerivers<Field>(): {
if (!complexTypes.has(typeof typeObj))
throw Error(`provable: unsupported type "${typeObj}"`);

if (Array.isArray(typeObj))
if (Array.isArray(typeObj)) {
if (!Array.isArray(obj)) {
throw Error(`Expected an array for type, but got ${typeof obj}`);
}
if (typeObj.length !== obj.length) {
throw Error(
`Expected array length ${typeObj.length}, but got ${obj.length}`
);
}
return typeObj.map((t, i) => toFields(t, obj[i])).flat();
}

if (isProvable(typeObj)) return typeObj.toFields(obj);

Expand Down
Loading