import { addProvider, fromTypeUrl, getMessageType, toTypeUrl } from "./provider.mjs"; //#region src/message.d.ts /** * @fileOverview Contains basic helper methods to encode/format/mock a protobuf message * @module @ocap/message * @requires @ocap/util * @requires @ocap/proto * @example * bun add @ocap/message * * const { createMessage, fakeMessage, formatMessage } = require('@ocap/message'); */ declare const Any: any; declare const Timestamp: any; interface AnyData { type?: string; typeUrl?: string; value?: unknown; } interface TimestampData { seconds?: number; nanos?: number; } interface BigIntData { value?: Uint8Array; minus?: boolean; } interface ProtobufMessage { toObject(): Record; serializeBinary(): Uint8Array; [key: string]: unknown; } /** * Generated a fake message for a type, the message can be RPC request/response * * @public * @static * @param type - Message type string, should be defined in forge-abi or forge-core-protocol * @returns object */ declare function fakeMessage(type?: string): unknown; /** * Format an message from RPC to UI friendly * * @public * @static * @param type - input type * @param data - input data * @returns object [almost same structure as input] */ declare function formatMessage(type: string, data: Record): Record; /** * Create an protobuf encoded Typed message with specified data, ready to send to rpc server * * @public * @static * @param type - message type defined in forge-proto * @param params - message content * @returns Message instance */ declare function createMessage(type: string, params?: Record): ProtobufMessage | undefined; /** * Decode an google.protobuf.Any%{ typeUrl, value } => { type, value } * * @public * @static * @param data - encoded data object * @returns Object { type, value } */ declare function decodeAny(data: AnyData | null): AnyData; /** * Encode { type, value } => google.protobuf.Any%{ typeUrl, value } * Does nothing on already encoded message * * @public * @static * @param data * @returns google.protobuf.Any */ declare function encodeAny(data: AnyData | undefined): typeof Any | undefined; /** * Convert an { seconds, nanos } | date-string to google.protobuf.Timestamp object * * @public * @static * @param value * @returns instanceof google.protobuf.Timestamp */ declare function encodeTimestamp(value: string | TimestampData | undefined): typeof Timestamp | undefined; /** * Decode google.protobuf.Timestamp message to ISO Date String * * FIXME: node strictly equal because we rounded the `nanos` field * * @public * @static * @param data * @returns String timestamp */ declare function decodeTimestamp(data: TimestampData): string; interface BigIntProtobufMessage extends ProtobufMessage { setValue(v: Uint8Array): void; setMinus(v: boolean): void; } /** * Encode BigUint and BigSint types defined in forge-sdk, double encoding is avoided * * @public * @static * @param value - value to encode * @param type - type names defined in forge-proto * @returns Message */ declare function encodeBigInt(value: unknown, type: string): BigIntProtobufMessage; /** * Convert BigUint and BigSint to string representation of numbers * * @public * @static * @link https://stackoverflow.com/questions/23948278/how-to-convert-byte-array-into-a-signed-big-integer-in-javascript * @param data - usually from encodeBigInt * @returns human readable number */ declare function decodeBigInt(data: BigIntData): string; /** * Attach an $format method to rpc response * * @private * @param data * @param type */ declare function attachFormatFn(type: string, data: Record, key?: string): void; /** * Attach an example method to * * @private * @param data * @param type */ declare function attachExampleFn(type: string, host: Record, key: string): void; //#endregion export { AnyData, addProvider, attachExampleFn, attachFormatFn, createMessage, decodeAny, decodeBigInt, decodeTimestamp, encodeAny, encodeBigInt, encodeTimestamp, fakeMessage, formatMessage, fromTypeUrl, getMessageType, toTypeUrl };