import { CommitmentCiphertextStruct as CommitmentCiphertextStructV2 } from '../abi/typechain/RailgunSmartWallet'; import { PublicInputsRailgun } from '../models/prover-types'; import { TransactNote } from '../note/transact-note'; import { UnshieldNote } from '../note/unshield-note'; import { SpendingPublicKey, ViewingKeyPair } from '../key-derivation/wallet-node'; import { ClearSignDecodedNoteOutput, ClearSignDecodedOutput, ClearSignDecodedUnshieldOutput, ClearSignResult } from '../wallet/clear-sign'; /** * Ledger clear-sign verification core (V2). * * The device chooses each output's randomness and produces its ciphertext, so every value * it returns is untrusted input. This module is the only place that turns device bytes * into engine values, and it refuses to do so unless the output verifies against the note * the user actually approved. * * Why this is not optional: the SNARK constrains `boundParamsHash` and the signature — * it says nothing about ciphertext *contents*. A device returning a correctly-signed * tuple whose ciphertext encrypts different values would produce a perfectly valid * on-chain commitment that the recipient can never decrypt. The funds would be * unspendable forever, and the host would see success. These checks are what stand * between a firmware bug and burned money. */ /** What the caller needs to rebuild publicInputs/privateInputs for one output. */ export type VerifiedClearSignNote = { readonly notePublicKey: bigint; readonly hash: bigint; readonly commitmentCiphertext: CommitmentCiphertextStructV2; }; /** * Verify one device-generated note output against the approved note, and rebuild the * commitment and ciphertext from the device's randomness. * * Throws on any mismatch. Never returns partially-verified data. */ export declare const verifyClearSignNoteOutput: (note: TransactNote, decoded: ClearSignDecodedOutput, senderViewingKeys: ViewingKeyPair, senderMasterPublicKey: bigint) => Promise; /** * The device returns the message it signed. Recompute it from the rebuilt inputs and * require agreement, then check the signature itself against the wallet's spending public * key. * * Both run before proof generation deliberately. The circuit does verify the signature — * but only after a full proving run, and it surfaces as an opaque witness-generation * failure pointing nowhere near the device. Here the error names the cause. */ export declare const assertDeviceSignature: (publicInputs: PublicInputsRailgun, spendingPublicKey: SpendingPublicKey, result: Pick) => void; /** * Verify every device output and rebuild the engine-ordered notes and ciphertext. * * `sourceIndices` un-permutes: device responses arrive aligned to the *canonically sorted* * request, while `finalizeTransactionRequest` expects engine order. Walking the * permutation is what keeps each note paired with its own ciphertext. */ export declare const verifyAndRebuildClearSignOutputs: (internalOutputs: readonly TransactNote[], unshieldNote: Optional, sourceIndices: readonly (number | null)[], result: ClearSignResult, senderViewingKeys: ViewingKeyPair, senderMasterPublicKey: bigint) => Promise<{ internalOutputs: TransactNote[]; commitmentCiphertext: CommitmentCiphertextStructV2[]; }>; /** * An unshield note has no randomness at all — `npk` is the recipient address and the * commitment is a pure function of (toAddress, tokenData, value). So the host computes it * and compares; adopting the device's value would trust it for nothing in return. */ export declare const verifyClearSignUnshieldOutput: (note: UnshieldNote, decoded: ClearSignDecodedOutput) => bigint; export type { ClearSignDecodedNoteOutput, ClearSignDecodedUnshieldOutput };