mina-attestations
Version:
Private Attestations on Mina
45 lines (44 loc) • 1.87 kB
TypeScript
/**
* Misc gadgets for attestation contracts.
*/
import { Bool, Field, TupleN, UInt32, UInt64, UInt8 } from 'o1js';
export { pack, unpack, packBytes, unpackBytes, uint64FromBytesBE, uint64ToBytesBE, lessThan16, assertInRange16, assertLessThan16, rangeCheck, };
/**
* Pack a list of fields of bit size `chunkSize` each into a single field.
* Uses little-endian encoding.
*
* **Warning**: Assumes, but doesn't prove, that each chunk fits in the chunk size.
*/
declare function pack(chunks: Field[], chunkSize: number): Field;
/**
* Unpack a field into a list of fields of bit size `chunkSize` each.
* Uses little-endian encoding.
*
* Proves that the output fields have at most `chunkSize` bits,
* and that the input has at most `chunkSize * numChunks` bits.
*/
declare function unpack<N extends number>(word: Field | bigint, chunkSize: 1 | 4 | 8 | 16 | 32 | 64, numChunks: N): TupleN<import("node_modules/o1js/dist/node/lib/provable/field.js").Field, N>;
declare function packBytes(bytes: UInt8[]): import("node_modules/o1js/dist/node/lib/provable/field.js").Field;
declare function unpackBytes(word: Field, numBytes: number): UInt8[];
declare function uint64FromBytesBE(bytes: UInt8[]): UInt64;
declare function uint64ToBytesBE(x: UInt64): UInt8[];
declare function rangeCheck(x: Field, bits: 1 | 4 | 8 | 16 | 32 | 64): void;
/**
* Asserts that 0 <= i <= x without other assumptions on i,
* assuming that 0 <= x < 2^16.
*/
declare function assertInRange16(i: Field, x: Field | number): void;
/**
* Asserts that i < x, assuming that i in [0,2^32) and x in [0,2^16).
*
* Cost: 1.5
*/
declare function assertLessThan16(i: UInt32, x: Field | number): void;
/**
* Returns i <? x for i, x < 2^16.
*
* Note: This is also sound for i < 2^32, just not complete in that case
*
* Cost: 2.5
*/
declare function lessThan16(i: Field, x: Field | number): Bool;