UNPKG

@xpla/xpla

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/545047/188804067-28e67e5e-0214-4449-ab04-2e0c564a6885.svg" width="80"> </p>

105 lines (104 loc) 3.98 kB
import { SignatureFormatFunction } from "@interchainjs/auth"; import { BaseCryptoBytes } from "@interchainjs/utils"; //#region src/signers/signature-processor.d.ts /** * Utility functions that implement the BytesUtils functionality mentioned in requirements * Defined first to avoid forward reference issues */ declare const BytesUtils: { /** * Split signature into components */ splitSignature: (signature: Uint8Array) => { r: Uint8Array; s: Uint8Array; recovery?: number; }; /** * Combine signature components */ combineSignature: (r: Uint8Array, s: Uint8Array, recovery?: number) => Uint8Array; /** * Convert to Uint8Array (arrayify equivalent) */ arrayify: (data: Uint8Array) => Uint8Array; /** * Concatenate byte arrays */ concat: (arrays: Uint8Array[]) => Uint8Array; }; /** * CosmosEvm signature format function type * Takes raw signature bytes and returns processed signature bytes */ type CosmosEvmSignatureFormatFunction = (signature: Uint8Array) => Uint8Array; /** * Preset CosmosEvm signature format functions mapping * These implement the CosmosEvmSignatureFormat enum (COMPACT, FULL, RAW) mentioned in requirements */ declare const PRESET_COSMOS_EVM_SIGNATURE_FORMATS: Record<string, CosmosEvmSignatureFormatFunction>; /** * Resolve CosmosEvm signature format function * @param formatFn - Format function or string identifier * @param defaultFn - Default format to use if formatFn is not provided * @returns Resolved signature format function */ declare function resolveCosmosEvmSignatureFormat(formatFn?: CosmosEvmSignatureFormatFunction | string, defaultFn?: CosmosEvmSignatureFormatFunction | string): CosmosEvmSignatureFormatFunction | undefined; /** * Utility class for processing CosmosEvm signatures * Implements the configurable signature post-processing logic * that was previously hardcoded in EthSecp256k1Signature.toCompact() */ declare class CosmosEvmSignatureProcessor { /** * Process a signature according to the specified format * @param signature - Raw signature bytes (typically 65 bytes with recovery) * @param format - Desired signature format (string or function) * @returns Processed signature bytes */ static processSignature(signature: Uint8Array, format?: SignatureFormatFunction | string): Uint8Array; /** * Convert signature to BaseCryptoBytes for use in workflows * @param signature - Signature bytes * @param format - Desired signature format * @returns BaseCryptoBytes instance */ static toBaseCryptoBytes(signature: Uint8Array, format?: SignatureFormatFunction | string): BaseCryptoBytes; } /** * Legacy compatibility class that implements the EthSecp256k1Signature interface * This provides backward compatibility for code that expects the old toCompact() method */ declare class EthSecp256k1Signature { readonly signature: Uint8Array; constructor(signature: Uint8Array); /** * Convert signature to compact format * This method maintains backward compatibility with the original implementation * @returns Compact signature as BaseCryptoBytes (Key-like object) */ toCompact(): BaseCryptoBytes; /** * Convert signature to full format * @returns Full signature as BaseCryptoBytes */ toFull(): BaseCryptoBytes; /** * Get raw signature * @returns Raw signature as BaseCryptoBytes */ toRaw(): BaseCryptoBytes; /** * Process signature with configurable format * @param format - Desired signature format * @returns Processed signature as BaseCryptoBytes */ process(format: SignatureFormatFunction | string): BaseCryptoBytes; } /** * Type alias for backward compatibility * Represents the Key class mentioned in the original requirements */ type Key = BaseCryptoBytes; //#endregion export { BytesUtils, CosmosEvmSignatureFormatFunction, CosmosEvmSignatureProcessor, EthSecp256k1Signature, Key, PRESET_COSMOS_EVM_SIGNATURE_FORMATS, resolveCosmosEvmSignatureFormat };