/** * Owner authorization for the two BTC-custody steps — withdrawal **execute** * (`btc-transaction-signer`) and stale-spend **invalidate** * (`btc-utxo-invalidator`) — accepting BOTH the legacy EIP-191 signature over * the packed hash and the EIP-712 `*Request` typed signature * (`contracts/docs/EIP712_DOMAIN_SPEC.md` §3.8; plan * `docs/vigil/plans/2026-10-16-A2-eip712-withdrawal-authorization-plan.md`). * * ## Why a separate module (DR-4) * * `authorization.module.ts` is imported by nine actions. Changing it rotates * nine CIDs; this module is imported by exactly the two actions above, so * only their CIDs move. The legacy verifiers in `authorization.module.ts` are * called unchanged here and stay until the legacy arm is switched off. * * ## The typed message is built from ON-CHAIN values * * Destination, total deduction and outpoint come from the * `BTCSpendAuthorizer` record; the fee is the one the transaction is built * with; the input-set hash is computed over the inputs actually signed. A * valid typed signature therefore proves the borrower's wallet displayed * exactly what will be paid — no caller-supplied field enters the digest * except the position id and the quantum stamp, both of which the signature * binds as-is. * * ## Two arms, two calls (no scheme selector on the wire) * * 1. Legacy: the existing `AuthorizationModule` verifier, byte-for-byte * today's behaviour (execute: strict current quantum, audit H-3). * 2. Typed: `AuthorizationModule.verifyActionAuthorization` with the typed * encoding. Its legacy slot carries a sentinel, and `isAuthorized` accepts * ONLY the typed digest, so this call can never accept an EIP-191 * signature under the wider window. * * ## Execute window (DR-6) * * The typed execute arm accepts a stamp from the current OR the previous * quantum (`TYPED_EXECUTE_ACCEPTED_QUANTA`), never the next: a readable * prompt takes longer to read than a hash takes to ignore. The shared * verifier still waits out the dead zone and re-checks past/current/next * after the wait, so in practice a stamp from quantum S is accepted only when * verification starts by second 51 of quantum S+1 (the SDK's relay deadline * is set from this). * * That relaxes H-3 for the typed arm only, which is safe because the typed * message binds the destination, every amount, the fee and the full input * set: a late or replayed typed signature can only authorize a transaction * with the same outputs, fee and inputs. The input ORDER is not bound (the * set hash is order-independent), so a replay may produce a different txid * over the same inputs — two such transactions conflict and at most one * confirms, exactly as on the legacy arm inside its window. */ import { type BtcSpendRequestDomain, type BtcSpendRequestField, type BtcSpendRequestPrimaryType } from "../constants/btc-spend-request-types"; /** The action string the execute envelope binds (unchanged from the legacy form). */ export declare const EXECUTE_BTC_WITHDRAWAL_ACTION_STRING = "execute-btc-withdrawal"; /** * How many quanta the typed execute arm accepts: the current one and the one * before it (DR-6). A module constant, not a jsParam — a caller must never be * able to widen it. */ export declare const TYPED_EXECUTE_ACCEPTED_QUANTA = 2; export interface BtcSpendTypedMessage { domain: BtcSpendRequestDomain; types: Record; primaryType: BtcSpendRequestPrimaryType; message: Record; } /** The `BTCSpendAuthorizer.getAuthorizedSpends` row the signature consumes. */ export interface AuthorizedSpendRecord { txid: unknown; vout: unknown; targetAddress: unknown; targetAmount: unknown; } /** The execute envelope fields — the legacy verifier's `auth` argument. */ export interface ExecuteBtcWithdrawalAuth { positionId: string; timestamp: number; chainId: number; utxoIdentifier: string; networkFee: number; targetAddress: string; targetAmount: string | number | bigint; utxosHash: string; action: string; signature: string; } /** The invalidate envelope fields — the legacy verifier's `auth` argument. */ export interface InvalidateStaleSpendAuth { positionId: string; timestamp: number; chainId: number; utxoTxid: string; utxoVout: number; action: string; signature: string; } /** * Build the `ExecuteBtcWithdrawalRequest` the borrower's wallet signed, from * the on-chain record and the transaction's own fee and input set. * * @throws on a non-integer or negative fee, a fee that is not below the total * deduction, or a malformed record txid. */ export declare function buildExecuteBtcWithdrawalTypedMessage(params: { chainId: number; btcSpendAuthorizerAddress?: string; positionId: string; record: AuthorizedSpendRecord; networkFee: number; inputSetHash: string; quantumTimestamp: number; }): BtcSpendTypedMessage; /** * Build the `InvalidateStaleSpendRequest` the borrower's wallet signed, from * the on-chain record's outpoint. */ export declare function buildInvalidateStaleSpendTypedMessage(params: { chainId: number; btcSpendAuthorizerAddress?: string; positionId: string; record: AuthorizedSpendRecord; quantumTimestamp: number; }): BtcSpendTypedMessage; /** EIP-712 digest of a typed message, with the encoder the TEE runs. */ export declare function btcSpendTypedDigest(typed: BtcSpendTypedMessage): string; /** * Verify the borrower's (or, for a liquidated position, the PKP owner's) * consent to execute an authorized Bitcoin spend. * * Pre-checks repeat `verifyBtcExecutionAuthorization`'s: action string * (returns false), M-02 chain binding and the bytes32 input-set hash (throw). * * @param record - the on-chain `AuthorizedSpend` row for the outpoint being spent. * @param btcSpendAuthorizerAddress - the resolved authorizer; checked against the * pin on pinned chains, the domain source on hardhat. */ export declare function verifyExecuteBtcWithdrawalAuthorization(auth: ExecuteBtcWithdrawalAuth, record: AuthorizedSpendRecord, positionOwner: string, targetChainId: number, provider: unknown, btcSpendAuthorizerAddress: string): Promise; /** * Verify the borrower's consent to invalidate a stale authorized spend. * * Both arms keep `verifyRecoveryAuthorization`'s window (past, current or * next quantum; decision D-7). Pre-checks repeat its: action string (returns * false) and M-02 chain binding (throws). */ export declare function verifyInvalidateStaleSpendAuthorization(auth: InvalidateStaleSpendAuth, record: AuthorizedSpendRecord, positionOwner: string, targetChainId: number, provider: unknown, btcSpendAuthorizerAddress: string): Promise; //# sourceMappingURL=btc-spend-request-authorization.module.d.ts.map