declare function bytesToHex(bytes: Uint8Array): string; declare function hexToBytes(hex: string): Uint8Array; declare function with0x(value: string): string; declare function without0x(value: string): string; declare function utf8ToBytes(str: string): Uint8Array; declare function bytesToUtf8(bytes: Uint8Array): string; declare function asciiToBytes(str: string): Uint8Array; declare function bytesToAscii(bytes: Uint8Array): string; declare function concatBytes(...arrays: Uint8Array[]): Uint8Array; type IntegerType = number | string | bigint | Uint8Array; declare function intToBigInt(value: IntegerType): bigint; declare function intToBytes(value: IntegerType, byteLength: number): Uint8Array; declare function bigIntToBytes(value: bigint, length?: number): Uint8Array; declare function intToHex(integer: IntegerType, byteLength?: number): string; declare function toTwos(value: bigint, width: bigint): bigint; declare function fromTwos(value: bigint, width: bigint): bigint; declare function bytesToTwosBigInt(bytes: Uint8Array): bigint; declare function writeUInt32BE(value: number): Uint8Array; declare function readUInt32BE(bytes: Uint8Array, offset?: number): number; declare function writeUInt16BE(value: number): Uint8Array; declare function readUInt16BE(bytes: Uint8Array, offset?: number): number; declare function writeUInt8(value: number): Uint8Array; import { ripemd160 } from "@noble/hashes/legacy"; import { sha256 } from "@noble/hashes/sha2"; import { sha512_256 } from "@noble/hashes/sha2"; /** RIPEMD160(SHA256(input)) — standard Bitcoin/Stacks address hash */ declare function hash160(input: Uint8Array): Uint8Array; /** Hash used for transaction IDs */ declare function txidFromBytes(data: Uint8Array): string; /** hash160 as hex — used for P2PKH address derivation */ declare function hashP2PKH(input: Uint8Array): string; declare function c32address(version: number, hash160hex: string): string; declare function c32addressDecode(c32addr: string): [number, string]; /** * Derive the single-sig Stacks address for a compressed public key. */ declare function publicKeyToAddress(publicKey: string | Uint8Array, network?: "mainnet" | "testnet"): string; /** Clarity contract-name grammar: leading letter, then letters/digits/`-`/`_`. * Underscore is legal (SIP-002) and deployed contracts use it — matches the * pattern the Index API already accepts for contract ids. */ declare const CONTRACT_NAME_REGEX: RegExp; declare function validateStacksAddress(address: string): boolean; /** Alias for validateStacksAddress — matches future.md naming. */ declare const isValidAddress: (address: string) => boolean; /** Parse a principal into its parts, or null when malformed. The single * definition of "valid principal" for this package: exactly one optional * `.name` segment (never two), a c32-decodable address, and a contract name * matching the Clarity grammar. */ declare function parsePrincipal(value: string): { address: string contractName?: string } | null; /** Split `address.name` into its parts. Throws on anything `parsePrincipal` * rejects, and on a bare address with no contract name. */ declare function parseContractId(contractId: string): [string, string]; declare function isClarityName(name: string): boolean; /** * Compare two Stacks addresses for equality (case-insensitive, version-aware). * Throws if either address is invalid. */ declare function isAddressEqual(a: string, b: string): boolean; /** Extract the version byte from a Stacks address (22, 20, 26, or 21). */ declare function addressToVersion(address: string): number; /** * Build a contract address from deployer + contract name. * Validates both parts; returns `deployer.contractName`. */ declare function getContractAddress(deployer: string, contractName: string): string; declare const MAX_U128: bigint; declare const MAX_I128: bigint; declare const MIN_I128: bigint; /** C32-encoded address version bytes for single-sig and multi-sig on each network. */ declare const AddressVersion: { readonly MainnetSingleSig: 22 readonly MainnetMultiSig: 20 readonly TestnetSingleSig: 26 readonly TestnetMultiSig: 21 }; type AddressVersion = (typeof AddressVersion)[keyof typeof AddressVersion]; /** Mainnet burn address (all-zero hash160). */ declare const ZERO_ADDRESS = "SP000000000000000000002Q6VF78"; /** Testnet burn address (all-zero hash160). */ declare const TESTNET_ZERO_ADDRESS = "ST000000000000000000002AMW42H"; /** Number of microSTX per 1 STX (10^6). */ declare const MICROSTX_PER_STX = 1000000n; /** * Format a bigint value with decimal places. * @example formatUnits(1000000n, 6) → "1.0" * @example formatUnits(1500000n, 6) → "1.5" */ declare function formatUnits(value: bigint | number | string, decimals: number): string; declare function parseUnits(value: string | number, decimals: number): bigint; /** * Format microSTX to STX string (6 decimals). * @example formatStx(1000000n) → "1.0" */ declare function formatStx(microStx: bigint | number | string): string; /** * Parse STX string to microSTX bigint (6 decimals). * @example parseStx("1.5") → 1500000n */ declare function parseStx(stx: string | number): bigint; interface RecoverableSignature { /** Recovery id (0–3) */ recovery: number; /** 32-byte r value as hex */ r: string; /** 32-byte s value as hex */ s: string; } /** * Parse a 65-byte VRS hex signature into components. * VRS format: recovery (1 byte) + r (32 bytes) + s (32 bytes) */ declare function parseSignature(hex: string): RecoverableSignature; /** * Serialize a recoverable signature to 65-byte VRS hex (130 chars). */ declare function serializeSignature(sig: RecoverableSignature): string; /** Convert VRS hex to RSV hex: r+s (128 chars) + recovery (2 chars). */ declare function signatureVrsToRsv(vrs: string): string; /** Convert RSV hex to VRS hex: recovery (2 chars) + r+s (128 chars). */ declare function signatureRsvToVrs(rsv: string): string; /** * Recover a public key from a message hash and VRS signature. * @returns hex-encoded public key (33 bytes compressed, or 65 bytes uncompressed) */ declare function recoverPublicKey(hash: Uint8Array | string, signature: string, compressed?: boolean): string; /** * Recover a Stacks address from a message hash and VRS signature. * @param addressVersion defaults to MainnetSingleSig (22) */ declare function recoverAddress(hash: Uint8Array | string, signature: string, addressVersion?: number): string; /** * Verify an ECDSA signature against a message hash and public key. * Accepts compact (64-byte) signature as hex or Uint8Array. */ declare function verifySignature(hash: Uint8Array | string, signature: string | Uint8Array, publicKey: string | Uint8Array): boolean; /** * Verify a signed Stacks message. * Parses a VRS signature, extracts r+s for verification. * Falls back to legacy prefix if standard prefix fails. */ declare function verifyMessageSignature(message: string | Uint8Array, signature: string, publicKey: string): boolean; /** Compress a public key to 33 bytes (hex). */ declare function compressPublicKey(publicKey: string | Uint8Array): string; /** Uncompress a public key to 65 bytes (hex). */ declare function uncompressPublicKey(publicKey: string | Uint8Array): string; /** Check if a public key is in compressed format (starts with 0x02 or 0x03). */ declare function isCompressedPublicKey(publicKey: string | Uint8Array): boolean; /** Generate cryptographically secure random bytes. Defaults to 32 bytes. */ declare function randomBytes(length?: number): Uint8Array; export { writeUInt8, writeUInt32BE, writeUInt16BE, without0x, with0x, verifySignature, verifyMessageSignature, validateStacksAddress, utf8ToBytes, uncompressPublicKey, txidFromBytes, toTwos, signatureVrsToRsv, signatureRsvToVrs, sha512_256, sha256, serializeSignature, ripemd160, recoverPublicKey, recoverAddress, readUInt32BE, readUInt16BE, randomBytes, publicKeyToAddress, parseUnits, parseStx, parseSignature, parsePrincipal, parseContractId, isValidAddress, isCompressedPublicKey, isClarityName, isAddressEqual, intToHex, intToBytes, intToBigInt, hexToBytes, hashP2PKH, hash160, getContractAddress, fromTwos, formatUnits, formatStx, concatBytes, compressPublicKey, c32addressDecode, c32address, bytesToUtf8, bytesToTwosBigInt, bytesToHex, bytesToAscii, bigIntToBytes, asciiToBytes, addressToVersion, ZERO_ADDRESS, TESTNET_ZERO_ADDRESS, RecoverableSignature, MIN_I128, MICROSTX_PER_STX, MAX_U128, MAX_I128, IntegerType, CONTRACT_NAME_REGEX, AddressVersion };