/** * @file Hive protocol serialization. * @author Johan Nordberg * @license * Copyright (c) 2017 Johan Nordberg. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistribution of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * You acknowledge that this software is not designed, licensed or intended for use * in the design, construction, operation or maintenance of any military facility. */ import { BinaryWriter } from "../utils.js"; import { PublicKey } from "../crypto.js"; import { Asset } from "./asset.js"; import { HexBuffer } from "./misc.js"; import { Operation } from "./operation.js"; /** * Function signature for writing one Hive protocol value to Pollen's native * byte writer. * * @param buffer - Destination binary writer. * @param data - Value to serialize. * * @remarks * Serializers are intentionally composable. Complex operation serializers are * built by combining primitive serializers for numbers, native `bigint`-backed * 64-bit values, strings, assets, public keys, arrays, options, and objects. * * @example * ```ts * const writer = new BinaryWriter() * Types.String(writer, 'pollen') * ``` */ export type Serializer = (buffer: BinaryWriter, data: any) => void; declare const VoidSerializer: (_buffer: BinaryWriter) => never; declare const StringSerializer: (buffer: BinaryWriter, data: string) => void; declare const Int8Serializer: (buffer: BinaryWriter, data: number) => void; declare const Int16Serializer: (buffer: BinaryWriter, data: number) => void; declare const Int32Serializer: (buffer: BinaryWriter, data: number) => void; declare const Int64Serializer: (buffer: BinaryWriter, data: number) => void; declare const UInt8Serializer: (buffer: BinaryWriter, data: number) => void; declare const UInt16Serializer: (buffer: BinaryWriter, data: number) => void; declare const UInt32Serializer: (buffer: BinaryWriter, data: number) => void; declare const UInt64Serializer: (buffer: BinaryWriter, data: number) => void; declare const BooleanSerializer: (buffer: BinaryWriter, data: boolean) => void; declare const StaticVariantSerializer: (itemSerializers: Serializer[]) => (buffer: BinaryWriter, data: [number, unknown]) => void; /** * Serialize asset. * * @remarks * This loses precision for amounts larger than 2^53-1/10^precision. * Should not be a problem in real-world usage. */ declare const AssetSerializer: (buffer: BinaryWriter, data: Asset | string | number) => void; declare const DateSerializer: (buffer: BinaryWriter, data: string) => void; declare const PublicKeySerializer: (buffer: BinaryWriter, data: PublicKey | string | null) => void; declare const BinarySerializer: (size?: number) => (buffer: BinaryWriter, data: Uint8Array | HexBuffer) => void; declare const FlatMapSerializer: (keySerializer: Serializer, valueSerializer: Serializer) => (buffer: BinaryWriter, data: [unknown, unknown][]) => void; declare const ArraySerializer: (itemSerializer: Serializer) => (buffer: BinaryWriter, data: unknown[]) => void; declare const ObjectSerializer: (keySerializers: [string, Serializer][]) => (buffer: BinaryWriter, data: any) => void; declare const OptionalSerializer: (valueSerializer: Serializer) => (buffer: BinaryWriter, data: unknown) => void; declare const OperationSerializer: (buffer: BinaryWriter, operation: Operation) => void; /** * Hive protocol serializer registry. * * @remarks * `Types` is the internal engine behind transaction signing, transaction id * generation, memo envelopes, and witness property encoding. Each member writes * one Hive-compatible value into a {@link BinaryWriter}, which is backed by * `Uint8Array` and `DataView` rather than legacy byte-buffer dependencies. The * object is exported for advanced protocol tooling, but most applications * should use higher-level helpers such as `client.broadcast`. * * @example * ```ts * const writer = new BinaryWriter() * Types.Transaction(writer, transaction) * * const bytes = writer.getBuffer() * ``` * * @throws Error * Individual serializers throw when a value cannot be represented in the * expected Hive wire format, such as a binary field with the wrong byte length * or an operation name with no registered serializer. */ export declare const Types: { Array: typeof ArraySerializer; Asset: typeof AssetSerializer; Authority: (buffer: BinaryWriter, data: any) => void; Binary: typeof BinarySerializer; Boolean: typeof BooleanSerializer; Date: typeof DateSerializer; EncryptedMemo: (buffer: BinaryWriter, data: any) => void; FlatMap: typeof FlatMapSerializer; Int16: typeof Int16Serializer; Int32: typeof Int32Serializer; Int64: typeof Int64Serializer; Int8: typeof Int8Serializer; Object: typeof ObjectSerializer; Operation: typeof OperationSerializer; Optional: typeof OptionalSerializer; Price: (buffer: BinaryWriter, data: any) => void; PublicKey: typeof PublicKeySerializer; StaticVariant: typeof StaticVariantSerializer; String: typeof StringSerializer; Transaction: (buffer: BinaryWriter, data: any) => void; UInt16: typeof UInt16Serializer; UInt32: typeof UInt32Serializer; UInt64: typeof UInt64Serializer; UInt8: typeof UInt8Serializer; Void: typeof VoidSerializer; }; export {};