/** * Invalidator-transaction output classification (stale-spend recovery, Phase 2 * of audit #62210). Pure logic extracted from `stale-spend-recovery-validator` * so the classifier — the decision that gates a `StaleSpendRecovery` * attestation — is directly unit-testable (remediation P2/#19). * * Zero imports by design: values arrive pre-normalized (lowercase addresses, * bigint sats) and the policy bounds — the max fee and the dust allowance — * are parameters, so this module never touches the Lit runtime, ethers, or * the constants chunk. */ export type RecoveryClassification = "invalidated" | "consumed-as-authorized"; /** One output of the invalidator tx, pre-normalized by the caller. */ export interface NormalizedOutput { /** Lowercased scriptpubkey_address; empty string when the provider omitted it. */ addressLc: string; /** Output value in sats. */ value: bigint; } /** * Classify an invalidator transaction's outputs against the on-chain * AuthorizedSpend. Throws on every suspicious shape (fail-closed); returns * the classification only when the tx provably either returned the funds to * the vault ("invalidated") or executed exactly the authorized spend * ("consumed-as-authorized"). * * Invariants enforced: * - No output may pay an address other than the vault or the authorized target. * - "invalidated" (no target outputs): the vault must receive the FULL input * value minus at most `maxFeeSats` (remediation #19 — previously this * branch had no value bound at all, so a tx returning 1 sat of a large * input to the vault still attested as "invalidated", releasing the * on-chain reservation while the position silently lost the difference to * fees). The vault total may also never exceed the input value. * - "consumed-as-authorized" (target outputs present): exactly one target * output, at most one vault output, the target is paid no more than the * borrower-signed `authorizedTargetAmount`, the amount leaving the vault * must equal that amount (M-C), and the tx's implied miner fee must be * non-negative and within `maxFeeSats`. * * The M-C vault-change identity has ONE exemption, and it is not a loosening * of the rule — it is the rule applied to a transaction the signer is * structurally incapable of shaping any other way. `modules/bitcoin/transaction` * folds sub-dust change into the miner fee rather than emitting a * non-standard output that the network would refuse to relay, so a withdrawal * leaving less than the dust threshold in change has NO vault leg at all. * Demanding `vaultOutput == inputValue - authorizedTargetAmount` from such a * tx demands an output that cannot exist, which permanently bricked the * reservation it was meant to release (mainnet 2026-08-28: inputs=40000, * authorized=39936, change=64 < 294-sat P2WPKH dust). The exemption is * therefore admitted only when the vault leg is ABSENT and the change it * would have carried is below `dustAllowanceSats`; a vault output that EXISTS * must still carry the exact change. * * The target leg is bounded from BOTH sides, and it needs both because the * consumed branch previously never examined that output's value at all: * - Below, by the implied miner fee (`inputValue - sum(outputs)`) being * within `maxFeeSats` — otherwise, with the dust exemption admitted and no * vault leg to pin the arithmetic, an unbounded share of the borrower's * authorized amount could go to miners instead of to them. * - Above, by an explicit `targetOutput <= authorizedTargetAmount`. The fee * bound does NOT imply this on the dust-folded path: `fee >= 0` only gives * `targetOutput <= inputValue`, and there `inputValue` exceeds the * authorized amount by exactly the folded change, so that surplus could * otherwise be paid to the target rather than to miners. * * `maxFeeSats` must admit every builder whose transactions reach this * classifier — the fixed-shape invalidator AND the size-aware withdrawal * signer, whose ceiling overtakes a flat cap from two inputs up. Passing a * bound tighter than the one the signer itself enforced re-creates the very * failure this fix exists to remove: a legitimately signed spend that can * never be attested, and a reservation stuck forever. */ export declare function classifyInvalidatorTransaction(params: { outputs: NormalizedOutput[]; vaultAddressLc: string; targetAddressLc: string; /** Sum of all input prevout values (sats). */ inputValue: bigint; authorizedTargetAmount: bigint; /** Max acceptable miner fee (sats) on either classification path. */ maxFeeSats: bigint; /** * Largest standard dust threshold (sats) across every scriptPubKey type the * vault may use — 546 (legacy), which bounds P2WPKH's 294 and * P2WSH/P2TR's 330. Change strictly below this may have been folded into * the miner fee instead of emitted as a vault output. Deliberately the MAX * rather than the vault's script-specific threshold: the tight per-script * table lives in the tx builder, and a second copy here is exactly the * divergence that caused the incident. The cost of the looser bound is * capped at `dustAllowanceSats - 1` sats leaving the vault beyond the * authorized amount, and only on a PKP-signed tx. */ dustAllowanceSats: bigint; }): RecoveryClassification; //# sourceMappingURL=invalidator-classification.d.ts.map