UNPKG

mina-attestations

Version:
74 lines (73 loc) 2.22 kB
import { Bytes, type ProvableHashable, UInt8 } from 'o1js'; import { DynamicArray, DynamicArrayBase } from './dynamic-array.ts'; import type { ProvableHashablePure } from '../o1js-missing.ts'; export { DynamicBytes, DynamicBytesBase }; type DynamicBytes = DynamicBytesBase; /** * Specialization of `DynamicArray` to bytes, * with added helper methods to convert instances to/from values. * * ```ts * const Bytes = DynamicBytes({ maxLength: 120 }); * * let bytes = Bytes.fromString('hello'); * let bytes2 = Bytes.fromBytes([1, 2, 3]); * * let string = bytes.toString(); * let uint8array = bytes2.toBytes(); * ``` */ declare function DynamicBytes({ maxLength, }: { maxLength: number; }): typeof DynamicBytesBase & { /** * Create DynamicBytes from a byte array in various forms. * * ```ts * let bytes = Bytes.fromBytes([1, 2, 3]); * ``` */ fromBytes(bytes: Uint8Array | (number | bigint | UInt8)[] | Bytes): DynamicBytes; /** * Create DynamicBytes from a hex string. * * ```ts * let bytes = Bytes.fromHex('010203'); * ``` */ fromHex(hex: string): DynamicBytes; /** * Create DynamicBytes from a string. */ fromString(s: string): DynamicBytes; provable: ProvableHashablePure<DynamicBytes, Uint8Array>; }; declare namespace DynamicBytes { var fromBytes: (bytes: Uint8Array) => DynamicBytesBase; var from: (input: DynamicArray<UInt8> | Uint8Array | string | (number | UInt8)[]) => DynamicBytes; var Base: typeof DynamicBytesBase; } declare class DynamicBytesBase extends DynamicArrayBase<UInt8, { value: bigint; }> { get innerType(): ProvableHashable<UInt8, { value: bigint; }>; /** * Hash the bytes using variants of SHA2. */ hashToBytes(algorithm: 'sha2-256' | 'sha2-384' | 'sha2-512'): import("node_modules/o1js/dist/node/lib/provable/bytes.js").Bytes; /** * Convert DynamicBytes to a byte array. */ toBytes(): Uint8Array; /** * Convert DynamicBytes to a hex string. */ toHex(): string; /** * Convert DynamicBytes to a string. */ toString(): string; growMaxLengthTo(maxLength: number): DynamicBytes; }