import { BigNumber } from '@bsv/sdk'; import { Chain } from '../../../../sdk/types'; import { ChaintracksFsApi } from '../Api/ChaintracksFsApi'; import { BulkHeaderFileInfo } from './BulkHeaderFile'; import { ChaintracksFetchApi } from '../Api/ChaintracksFetchApi'; import { BaseBlockHeader, BlockHeader } from '../../../../sdk/WalletServices.interfaces'; /** * Computes sha256 hash of file contents read as bytes with no encoding. * @param filepath Full filepath to file. * @param bufferSize Optional read buffer size to use. Defaults to 80,000 bytes. Currently ignored. * @returns `{hash, length}` where `hash` is base64 string form of file hash and `length` is file length in bytes. */ export declare function sha256HashOfBinaryFile(fs: ChaintracksFsApi, filepath: string, bufferSize?: number): Promise<{ hash: string; length: number; }>; /** * Validates the contents of a bulk header file. * @param bf BulkHeaderFileInfo containing `data` to validate. * @param prevHash Required previous header hash. * @param prevChainWork Required previous chain work. * @param fetch Optional ChaintracksFetchApi instance for fetching data. * @returns Validated BulkHeaderFileInfo with `validated` set to true. */ export declare function validateBulkFileData(bf: BulkHeaderFileInfo, prevHash: string, prevChainWork: string, fetch?: ChaintracksFetchApi): Promise; /** * Validate headers contained in an array of bytes. The headers must be consecutive block headers, 80 bytes long, * where the hash of each header equals the previousHash of the following header. * @param buffer Buffer of headers to be validated. * @param previousHash Expected previousHash of first header. * @param offset Optional starting offset within `buffer`. * @param count Optional number of headers to validate. Validates to end of buffer if missing. * @param previousChainWork Optional chain work through `previousHash`; when present, the result carries it forward. * @param chain Optional chain the headers belong to. Selects its proof-of-work limit * (see `proofOfWorkLimitBits`); omitted means the mainnet limit. * @returns Header hash of last header validated or previousHash if there where none. */ export declare function validateBufferOfHeaders(buffer: Uint8Array, previousHash: string, offset?: number, count?: number, previousChainWork?: string, chain?: Chain): { lastHeaderHash: string; lastChainWork: string | undefined; }; /** * Verifies that buffer begins with valid genesis block header for the specified chain. * @param buffer * @param chain */ export declare function validateGenesisHeader(buffer: Uint8Array, chain: Chain): void; /** * @param work chainWork as a BigNumber * @returns Converted chainWork value from BN to hex string of 32 bytes. */ export declare function workBNtoBuffer(work: BigNumber): string; /** * Returns true if work1 is more work (greater than) work2 */ export declare function isMoreWork(work1: string, work2: string): boolean; /** * Add two Buffer encoded chainwork values * @returns Sum of work1 + work2 as Buffer encoded chainWork value */ export declare function addWork(work1: string, work2: string): string; /** * Subtract Buffer encoded chainwork values * @returns work1 - work2 as Buffer encoded chainWork value */ export declare function subWork(work1: string, work2: string): string; /** * Computes "target" value for 4 byte Bitcoin block header "bits" value. * @param bits number or converted from Buffer using `readUint32LE` * @returns 32 byte Buffer with "target" value */ export declare function convertBitsToTarget(bits: number | number[]): BigNumber; /** * Computes "chainWork" value for 4 byte Bitcoin block header "bits" value. * @param bits number or converted from Buffer using `readUint32LE` * @param chain Optional chain the header belongs to. Selects its proof-of-work limit * (see `proofOfWorkLimitBits`); omitted means the mainnet limit. * @returns 32 byte Buffer with "chainWork" value */ export declare function convertBitsToWork(bits: number | number[], chain?: Chain): string; export declare function deserializeBaseBlockHeaders(buffer: number[] | Uint8Array, offset?: number, count?: number | undefined): BaseBlockHeader[]; export declare function deserializeBlockHeaders(firstHeight: number, buffer: number[] | Uint8Array, offset?: number, count?: number | undefined): BlockHeader[]; /** * Validates the exact data representation of an unpositioned 80-byte block * header before it reaches a chain lookup, queue, or serializer. */ export declare function validateBaseBlockHeaderFormat(header: BaseBlockHeader): void; export declare function validateHeaderFormat(header: BlockHeader): void; /** * Ensures that a header has a valid proof-of-work target and hash. * * @param hash The header hash, big-endian. * @param bits The header's compact target. * @param chain Optional chain the header belongs to. Selects its proof-of-work limit * (see `proofOfWorkLimitBits`); omitted means the mainnet limit. * * @returns true if the header is valid */ export declare function validateHeaderDifficulty(hash: number[] | Uint8Array, bits: number, chain?: Chain): boolean; /** * The compact encoding of the highest proof-of-work target `chain` admits. * * Only `'regtest'` raises the limit. Every other chain — and an omitted chain, * which is how every caller that predates this parameter asks — keeps the mainnet * limit, so no existing validation is relaxed. */ export declare function proofOfWorkLimitBits(chain?: Chain): number; /** * Ensures that a structured header's computed hash satisfies its declared * proof-of-work target. * * @param header Header whose format and hash have already been checked. * @param chain Optional chain the header belongs to. Selects its proof-of-work limit * (see `proofOfWorkLimitBits`); omitted means the mainnet limit. * @returns true if the header has valid proof-of-work. * @publicbody */ export declare function validateHeaderProofOfWork(header: BlockHeader, chain?: Chain): true; /** * Computes double sha256 hash of bitcoin block header * bytes are reversed to bigendian order * * If header is a Buffer, it is required to 80 bytes long * and in standard block header serialized encoding. * * @returns doule sha256 hash of header bytes reversed * @publicbody */ export declare function blockHash(header: BaseBlockHeader | number[] | Uint8Array): string; /** * Serializes a block header as an 80 byte Buffer. * The exact serialized format is defined in the Bitcoin White Paper * such that computing a double sha256 hash of the buffer computes * the block hash for the header. * @returns 80 byte Buffer * @publicbody */ export declare function serializeBaseBlockHeader(header: BaseBlockHeader, buffer?: number[], offset?: number): number[]; export declare function serializeBaseBlockHeaders(headers: BlockHeader[]): Uint8Array; /** * Deserialize a BaseBlockHeader from an 80 byte buffer * @publicbody */ export declare function deserializeBaseBlockHeader(buffer: number[] | Uint8Array, offset?: number): BaseBlockHeader; export declare function deserializeBlockHeader(buffer: number[] | Uint8Array, height: number, offset?: number): BlockHeader; /** * Returns the genesis block for the specified chain. * @publicbody */ export declare function genesisHeader(chain: Chain): BlockHeader; /** * Returns the genesis block for the specified chain. * @publicbody */ export declare function genesisBuffer(chain: Chain): number[]; /** * Returns a copy of a Buffer with byte order reversed. * @returns new buffer with byte order reversed. * @publicbody */ export declare function swapByteOrder(buffer: number[]): number[]; /** * @param num a number value in the Uint32 value range * @param littleEndian true for little-endian byte order in Buffer * @returns four byte buffer with Uint32 number encoded * @publicbody */ export declare function convertUint32ToBuffer(n: number, littleEndian?: boolean): number[]; export declare function writeUInt32LE(n: number, a: number[] | Uint8Array, offset: number): number; export declare function writeUInt32BE(n: number, a: number[] | Uint8Array, offset: number): number; export declare function readUInt32LE(a: number[] | Uint8Array, offset: number): number; export declare function readUInt32BE(a: number[] | Uint8Array, offset: number): number; /** * @param buffer four byte buffer with Uint32 number encoded * @param littleEndian true for little-endian byte order in Buffer * @returns a number value in the Uint32 value range * @publicbody */ export declare function convertBufferToUint32(buffer: number[] | Uint8Array, littleEndian?: boolean): number; //# sourceMappingURL=blockHeaderUtilities.d.ts.map