UNPKG

mina-attestations

Version:
39 lines (38 loc) 1.65 kB
/** * Gadgets to convert any field element to/from digits in some base. */ import { Field } from 'o1js'; import { DynamicArray } from './dynamic-array.ts'; import { DynamicString } from './dynamic-string.ts'; export { toDecimalString, toBaseBE, fromBaseBE }; /** * Computes the unique decimal string representation of `value`. * * You need to pass in the maximum supported number of digits `maxDigits`. * * The method costs about `10 * maxDigits` constraints. */ declare function toDecimalString(value: Field, maxDigits: number): DynamicString; /** * Computes a variable-length digit representation of `value` in base `base`. * * Returns a `DynamicArray` that starts with the **most significant digit**. * * The method guarantees that: * - The most significant digit is non-zero (unless the value is zero) * - The dynamic length of the array equals the minimum number of digits needed to represent the value. * - The output digits are in the range `[0, base)`. * * You need to pass in the maximum supported number of digits `maxDigits`, and the cost * in terms of constraints linearly depends on this value. */ declare function toBaseBE(value: Field, base: number, maxDigits: number): DynamicArray<Field, bigint>; /** * Recomputes the value from a variable-length digit representation in base `base`. * * Expects a `DynamicArray` that contains digits in big-endian order. * * Digits are _assumed_ (not proved) to be in the range `[0, base)` or a similarly * "small" range that guarantees that the digit sum doesn't wrap around the field. */ declare function fromBaseBE(digits: DynamicArray<Field>, base: number): Field;