import MerklePath from './MerklePath.js';
import Transaction from './Transaction.js';
import ChainTracker from './ChainTracker.js';
import BeefTx from './BeefTx.js';
import { Reader, Writer, ReaderUint8Array, WriterUint8Array } from '../primitives/utils.js';
export { BEEF_V1, BEEF_V2, ATOMIC_BEEF, TX_DATA_FORMAT } from './BeefConstants.js';
export declare class Beef {
    bumps: MerklePath[];
    txs: BeefTx[];
    version: number;
    atomicTxid: string | undefined;
    private txidIndex;
    private rawBytesCache?;
    private hexCache?;
    private needsSort;
    constructor(version?: number);
    private invalidateSerializationCaches;
    private markMutated;
    private ensureSerializableState;
    private ensureSortedForSerialization;
    private getSerializedBytes;
    private getBeefForAtomic;
    /**
     * @param txid of `beefTx` to find
     * @returns `BeefTx` in `txs` with `txid`.
     */
    findTxid(txid: string): BeefTx | undefined;
    private ensureTxidIndex;
    private deleteFromIndex;
    private addToIndex;
    /**
     * Replaces `BeefTx` for this txid with txidOnly.
     *
     * Replacement is done so that a `clone()` can be
     * updated by this method without affecting the
     * original.
     *
     * @param txid
     * @returns undefined if txid is unknown.
     */
    makeTxidOnly(txid: string): BeefTx | undefined;
    /**
     * @returns `MerklePath` with level zero hash equal to txid or undefined.
     */
    findBump(txid: string): MerklePath | undefined;
    /**
     * Finds a Transaction in this `Beef`
     * and adds any missing input SourceTransactions from this `Beef`.
     *
     * The result is suitable for signing.
     *
     * @param txid The id of the target transaction.
     * @returns Transaction with all available input `SourceTransaction`s from this Beef.
     */
    findTransactionForSigning(txid: string): Transaction | undefined;
    /**
     * Builds the proof tree rooted at a specific `Transaction`.
     *
     * To succeed, the Beef must contain all the required transaction and merkle path data.
     *
     * @param txid The id of the target transaction.
     * @returns Transaction with input `SourceTransaction` and `MerklePath` populated from this Beef.
     */
    findAtomicTransaction(txid: string): Transaction | undefined;
    /** Recursively attach merkle paths and source transactions to all inputs. */
    private addInputProof;
    private resolveInputSource;
    private attachMerklePathOrRecurse;
    /**
     * Merge a MerklePath that is assumed to be fully valid.
     * @param bump
     * @returns index of merged bump
     */
    mergeBump(bump: MerklePath): number;
    /**
     * Find an existing compatible bump or insert a new one; return its index.
     */
    private findOrInsertBump;
    /** If bump's level-0 path contains tx's txid, record the bumpIndex on tx. */
    private tryMarkTxProvenByBump;
    /**
     * Merge a serialized transaction.
     *
     * Checks that a transaction with the same txid hasn't already been merged.
     *
     * Replaces existing transaction with same txid.
     *
     * @param rawTx
     * @param bumpIndex Optional. If a number, must be valid index into bumps array.
     * @returns txid of rawTx
     */
    mergeRawTx(rawTx: number[] | Uint8Array, bumpIndex?: number): BeefTx;
    /**
     * Merge a `Transaction` and any referenced `merklePath` and `sourceTransaction`, recursifely.
     *
     * Replaces existing transaction with same txid.
     *
     * Attempts to match an existing bump to the new transaction.
     *
     * @param tx
     * @returns txid of tx
     */
    mergeTransaction(tx: Transaction): BeefTx;
    /**
     * Removes an existing transaction from the BEEF, given its TXID
     * @param txid TXID of the transaction to remove
     */
    removeExistingTxid(txid: string): void;
    mergeTxidOnly(txid: string): BeefTx;
    mergeBeefTx(btx: BeefTx): BeefTx;
    mergeBeef(beef: Beef | number[] | Uint8Array): void;
    /**
     * Sorts `txs` and checks structural validity of beef.
     *
     * Does NOT verify merkle roots.
     *
     * Validity requirements:
     * 1. No 'known' txids, unless `allowTxidOnly` is true.
     * 2. All transactions have bumps or their inputs chain back to bumps (or are known).
     * 3. Order of transactions satisfies dependencies before dependents.
     * 4. No transactions with duplicate txids.
     *
     * @param allowTxidOnly optional. If true, transaction txid only is assumed valid
     */
    isValid(allowTxidOnly?: boolean): boolean;
    /**
     * Sorts `txs` and confirms validity of transaction data contained in beef
     * by validating structure of this beef and confirming computed merkle roots
     * using `chainTracker`.
     *
     * Validity requirements:
     * 1. No 'known' txids, unless `allowTxidOnly` is true.
     * 2. All transactions have bumps or their inputs chain back to bumps (or are known).
     * 3. Order of transactions satisfies dependencies before dependents.
     * 4. No transactions with duplicate txids.
     *
     * @param chainTracker Used to verify computed merkle path roots for all bump txids.
     * @param allowTxidOnly optional. If true, transaction txid is assumed valid
     */
    verify(chainTracker: ChainTracker, allowTxidOnly?: boolean): Promise<boolean>;
    /**
     * Sorts `txs` and confirms validity of transaction data contained in beef
     * by validating structure of this beef.
     *
     * Returns block heights and merkle root values to be confirmed by a chaintracker.
     *
     * Validity requirements:
     * 1. No 'known' txids, unless `allowTxidOnly` is true.
     * 2. All transactions have bumps or their inputs chain back to bumps (or are known).
     * 3. Order of transactions satisfies dependencies before dependents.
     * 4. No transactions with duplicate txids.
     *
     * @param allowTxidOnly optional. If true, transaction txid is assumed valid
     * @returns {{valid: boolean, roots: Record<number, string>}}
     * `valid` is true iff this Beef is structuraly valid.
     * `roots` is a record where keys are block heights and values are the corresponding merkle roots to be validated.
     */
    verifyValid(allowTxidOnly?: boolean): {
        valid: boolean;
        roots: Record<number, string>;
    };
    /** Add txidOnly transaction txids; return false if not allowed. */
    private collectTxidOnlyTxids;
    /**
     * Record txids proven by bumps; validate all bump roots agree per block height.
     * Returns false if any root conflict is detected.
     */
    private collectBumpTxids;
    /** Verify that every tx with a bumpIndex has a matching txid leaf in its bump. */
    private verifyBumpIndexLeaves;
    /** Verify all input txids appear before the spending tx in sorted order. */
    private verifyInputDependencies;
    /** Confirm the computed merkle root for txid in bump matches previously accepted root for that height. */
    private confirmComputedRoot;
    /**
     * Serializes this data to `writer`
     * @param writer
     */
    toWriter(writer: Writer | WriterUint8Array): void;
    /**
     * Returns a binary array representing the serialized BEEF
     * @returns A binary array representing the BEEF
     * @returns An array of byte values containing binary serialization of the BEEF
     */
    toBinary(): number[];
    /**
     * Returns a binary array representing the serialized BEEF
     * @returns A Uint8Array containing binary serialization of the BEEF
     */
    toUint8Array(): Uint8Array;
    /**
     * Serialize this Beef as AtomicBEEF.
     *
     * `txid` must exist
     *
     * after sorting, if txid is not last txid, creates a clone and removes newer txs
     *
     * @param txid
     * @returns serialized contents of this Beef with AtomicBEEF prefix.
     */
    toBinaryAtomic(txid: string): number[];
    /**
     * Serialize this Beef as AtomicBEEF.
     *
     * `txid` must exist
     *
     * after sorting, if txid is not last txid, creates a clone and removes newer txs
     *
     * @param txid
     * @returns serialized contents of this Beef with AtomicBEEF prefix.
     */
    toUint8ArrayAtomic(txid: string): Uint8Array;
    /**
     * Returns a hex string representing the serialized BEEF
     * @returns A hex string representing the BEEF
     */
    toHex(): string;
    static fromReader(br: Reader | ReaderUint8Array): Beef;
    /**
     * Constructs an instance of the Beef class based on the provided binary array
     * @param bin The binary array or Uint8Array from which to construct BEEF
     * @returns An instance of the Beef class constructed from the binary data
     */
    static fromBinary(bin: number[] | Uint8Array): Beef;
    /**
     * Constructs an instance of the Beef class based on the provided string
     * @param s The string value from which to construct BEEF
     * @param enc The encoding of the string value from which BEEF should be constructed
     * @returns An instance of the Beef class constructed from the string
     */
    static fromString(s: string, enc?: 'hex' | 'utf8' | 'base64'): Beef;
    /**
     * Try to validate newTx.bumpIndex by looking for an existing bump
     * that proves newTx.txid
     *
     * @param newTx A new `BeefTx` that has been added to this.txs
     * @returns true if a bump was found, false otherwise
     */
    private tryToValidateBumpIndex;
    /**
     * Sort the `txs` by input txid dependency order:
     * - Oldest Tx Anchored by Path or txid only
     * - Newer Txs depending on Older parents
     * - Newest Tx
     *
     * with proof (MerklePath) last, longest chain of dependencies first
     *
     * @returns `{ missingInputs, notValid, valid, withMissingInputs }`
     */
    sortTxs(): {
        missingInputs: string[];
        notValid: string[];
        valid: string[];
        withMissingInputs: string[];
        txidOnly: string[];
    };
    /**
     * Partition txs into proven (result), txidOnly, and a queue of the rest.
     * Populates txidToTx and validTxids as side-effects.
     */
    private partitionTxs;
    /**
     * Separate queue entries that have at least one input txid not present in txidToTx.
     */
    private separateMissingInputs;
    /**
     * Topologically sort queue into result; return anything that cannot be sorted.
     */
    private topoSort;
    /**
     * @returns a shallow copy of this beef
     */
    clone(): Beef;
    /**
     * Ensure that all the txids in `knownTxids` are txidOnly
     * @param knownTxids
     */
    trimKnownTxids(knownTxids: string[]): void;
    /** Remove txidOnly entries that appear in knownTxids; return true if any were removed. */
    private removeKnownTxidOnlyTxs;
    /**
     * Remove bumps that are no longer referenced by any tx and update bumpIndex references.
     * Returns true if any bumps were removed.
     */
    private reindexBumps;
    /**
     * @returns array of transaction txids that either have a proof or whose inputs chain back to a proven transaction.
     */
    getValidTxids(): string[];
    /**
     * @returns Summary of `Beef` contents as multi-line string.
     */
    toLogString(): string;
    /**
   * In some circumstances it may be helpful for the BUMP MerklePaths to include
   * leaves that can be computed from row zero.
   */
    addComputedLeaves(): void;
    /** Add any missing computable leaf at `row` derived from two known leaves at `row - 1`. */
    private addComputedLeavesForRow;
}
export default Beef;
//# sourceMappingURL=Beef.d.ts.map