mina-attestations
Version:
Private Attestations on Mina
38 lines • 1.3 kB
JavaScript
/**
* Allows us to represent nested Provable types, to save us from always having to
* wrap types in `Struct` and similar.
*/
import { Struct, } from 'o1js';
import { array, ProvableType } from "./o1js-missing.js";
import { assertIsObject } from "./util.js";
export { NestedProvable, inferNestedProvable };
const NestedProvable = {
get: ((type) => {
return ProvableType.isProvableType(type)
? ProvableType.get(type)
: Struct(type);
}),
fromValue(value) {
try {
// case 1: value comes from a provable type
return ProvableType.fromValue(value);
}
catch {
// case 2: value is a record of values from provable types
if (typeof value === 'string')
return String;
if (Array.isArray(value))
return array(NestedProvable.fromValue(value[0]), value.length);
assertIsObject(value);
return Object.fromEntries(Object.entries(value).map(([key, value]) => [
key,
NestedProvable.fromValue(value),
]));
}
},
};
function inferNestedProvable(type) {
// TODO annoying that this cast doesn't work without overriding the type
return type;
}
//# sourceMappingURL=nested.js.map