/** * @file Misc utility functions. * @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 { NodeHealthTracker } from "./health-tracker.js"; /** * Context for smart retry and failover decisions. */ export interface RetryContext { healthTracker?: NodeHealthTracker; api?: string; isBroadcast?: boolean; consoleOnFailover?: boolean; } /** * Asserts that a condition is truthy. * * @param condition - The condition to check. * @param message - Optional error message. * * @throws Error * Thrown when `condition` is falsy. */ export declare function assert(condition: any, message?: string): asserts condition; /** * Converts a Uint8Array to a hex-encoded string. * * @param data - Native byte array to encode. * @returns Lowercase hex string with two characters per byte. * * @remarks * Pollen uses this helper at RPC and JSON boundaries where Hive expects binary * protocol values to be represented as hex text. * * @example * ```ts * const hex = toHex(new Uint8Array([0xde, 0xad, 0xbe, 0xef])) * ``` */ export declare function toHex(data: Uint8Array): string; /** * Converts a hex-encoded string to a Uint8Array. * * @param hex - Hex string with an even number of characters. * @returns Native bytes represented by the string. * * @throws Error * Thrown when `hex` has an odd number of characters. * * @example * ```ts * const bytes = fromHex('deadbeef') * ``` */ export declare function fromHex(hex: string): Uint8Array; /** * Concatenates multiple Uint8Arrays into one. * * @param arrays - Byte arrays to join in order. * @returns A new `Uint8Array` containing all input bytes. * * @remarks * This replaces Node `Buffer.concat` in protocol paths that must run the same * way in Node and browsers. * * @example * ```ts * const digestInput = concat([chainId, transactionBytes]) * ``` */ export declare function concat(arrays: Uint8Array[]): Uint8Array; /** * Compares two byte arrays for equality. * * @param a - First byte array. * @param b - Second byte array. * @returns True when both arrays have the same length and byte values. * * @example * ```ts * if (!bytesEqual(expected, actual)) { * throw new Error('checksum mismatch') * } * ``` */ export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean; /** * Growable little-endian byte writer used by Hive serializers. * * @remarks * The writer is built on `Uint8Array` and `DataView`, so protocol serialization * does not depend on Node `Buffer` or third-party byte-buffer packages. 64-bit * integers are accepted as `number`, decimal `string`, or native `bigint` and * are written in Hive's little-endian wire order. */ export declare class BinaryWriter { private buffer; private cursor; constructor(size?: number); private ensureCapacity; writeInt8(value: number): void; writeUint8(value: number): void; writeInt16(value: number): void; writeUint16(value: number): void; writeInt32(value: number): void; writeUint32(value: number): void; writeInt64(value: number | string | bigint): void; writeUint64(value: number | string | bigint): void; writeVarint32(value: number): void; writeString(value: string): void; writeBytes(bytes: Uint8Array): void; getBuffer(): Uint8Array; } /** * Little-endian byte reader used by Hive deserializers and memo decoding. * * @remarks * The constructor copies input into a clean `Uint8Array` before creating its * `DataView`. That avoids backing-store offset surprises from Buffer-like * views while preserving a browser-native byte engine. 64-bit readers return * native `bigint`, matching the Phase 8 removal of JSBI from the hot path. */ export declare class BinaryReader { private buffer; private view; private cursor; constructor(buffer: Uint8Array); readInt8(): number; readUint8(): number; readInt16(): number; readUint16(): number; readInt32(): number; readUint32(): number; readInt64(): bigint; readUint64(): bigint; readVarint32(): number; readString(): string; readBytes(length: number): Uint8Array; skip(length: number): void; } /** * Pauses execution for a fixed number of milliseconds. */ export declare function sleep(ms: number): Promise; /** * Converts an async iterator into a native Web ReadableStream. * * @remarks * This replaces the Node-specific `PassThrough` implementation with a browser-native * stream engine, enabling zero-dependency streaming in both environments. */ export declare function iteratorStream(iterator: AsyncIterableIterator): ReadableStream; /** * Creates a deep copy of a JSON-serializable object. */ export declare function copy(object: T): T; /** * Computes an exponential retry delay with random jitter. */ export declare function exponentialBackoffWithJitter(tries: number, baseDelay?: number, maxDelay?: number, jitter?: number): number; /** * Sends an RPC request with ordered node failover and health tracking. */ export declare function retryingFetch(currentAddress: string, allAddresses: string | string[], opts: RequestInit & { agent?: unknown; timeout?: number; }, timeout: number, failoverThreshold: number, consoleOnFailover: boolean, backoff: (tries: number) => number, fetchTimeout?: (tries: number) => number, retryContext?: RetryContext): Promise<{ response: any; currentAddress: string; }>; import { Asset, PriceType } from "./chain/asset.js"; import { WitnessSetPropertiesOperation } from "./chain/operation.js"; import { PublicKey } from "./crypto.js"; export interface WitnessProps { account_creation_fee?: string | Asset; account_subsidy_budget?: number; account_subsidy_decay?: number; key: PublicKey | string; maximum_block_size?: number; new_signing_key?: PublicKey | string | null; hbd_exchange_rate?: PriceType; hbd_interest_rate?: number; url?: string; } export declare const buildWitnessUpdateOp: (owner: string, props: WitnessProps) => WitnessSetPropertiesOperation; export declare const operationOrders: { vote: number; comment: number; transfer: number; transfer_to_vesting: number; withdraw_vesting: number; limit_order_create: number; limit_order_cancel: number; feed_publish: number; convert: number; account_create: number; account_update: number; witness_update: number; account_witness_vote: number; account_witness_proxy: number; pow: number; custom: number; report_over_production: number; delete_comment: number; custom_json: number; comment_options: number; set_withdraw_vesting_route: number; limit_order_create2: number; claim_account: number; create_claimed_account: number; request_account_recovery: number; recover_account: number; change_recovery_account: number; escrow_transfer: number; escrow_dispute: number; escrow_release: number; pow2: number; escrow_approve: number; transfer_to_savings: number; transfer_from_savings: number; cancel_transfer_from_savings: number; custom_binary: number; decline_voting_rights: number; reset_account: number; set_reset_account: number; claim_reward_balance: number; delegate_vesting_shares: number; account_create_with_delegation: number; witness_set_properties: number; account_update2: number; create_proposal: number; update_proposal_votes: number; remove_proposal: number; update_proposal: number; collateralized_convert: number; recurrent_transfer: number; fill_convert_request: number; author_reward: number; curation_reward: number; comment_reward: number; liquidity_reward: number; interest: number; fill_vesting_withdraw: number; fill_order: number; shutdown_witness: number; fill_transfer_from_savings: number; hardfork: number; comment_payout_update: number; return_vesting_delegation: number; comment_benefactor_reward: number; producer_reward: number; clear_null_account_balance: number; proposal_pay: number; sps_fund: number; hardfork_hive: number; hardfork_hive_restore: number; delayed_voting: number; consolidate_treasury_balance: number; effective_comment_vote: number; ineffective_delete_comment: number; sps_convert: number; expired_account_notification: number; changed_recovery_account: number; transfer_to_vesting_completed: number; pow_reward: number; vesting_shares_split: number; account_created: number; fill_collateralized_convert_request: number; system_warning: number; fill_recurrent_transfer: number; failed_recurrent_transfer: number; }; /** * Builds the two-word account-history operation mask accepted by Hive. * * @param allowedOperations - Operation ids from {@link operationOrders}. * @returns Low/high mask words as decimal strings, with zero words represented * as `null`. * * @remarks * Native `bigint` is used for the 64-bit mask words, replacing the older JSBI * shim while keeping the returned RPC shape as decimal strings or `null`. * * @example * ```ts * const mask = makeBitMaskFilter([ * operationOrders.transfer, * operationOrders.claim_reward_balance * ]) * ``` */ export declare function makeBitMaskFilter(allowedOperations: number[]): (string | null)[];