/// import { Signature } from '@railgun-community/circomlibjs'; import type { HDNodeWallet } from 'ethers'; import { PublicInputsRailgun } from '../models'; import { Database } from '../database/database'; import type { EphemeralSignerProvider } from './railgun-wallet'; import { SpendingKeyPair, SpendingPublicKey, ViewingKeyPair } from '../key-derivation/wallet-node'; import { RailgunWallet } from './railgun-wallet'; import { Prover } from '../prover/prover'; import { TXIDVersion } from '../models/poi-types'; import { SigningAttempt, SigningEnvelope } from '../solutions/nullifiers'; import { ClearSignConnectorResult, ClearSignMode, ClearSignResult, ClearSignTransactRequest } from './clear-sign'; /** * Mirrors the device library's connector signature. The optional 4th argument is the * clear-sign toggle: supply a plaintext transact and the device reviews it and generates * the output note ciphertexts itself; omit it and nothing changes. Both the argument and * the extra return data are optional, so existing blind-only connectors still satisfy * this type. */ export type ExternalSignerConnectorSignFn = (expectedHash: bigint, publicInputs?: PublicInputsRailgun, subSession?: string, clearSign?: ClearSignTransactRequest) => Promise; /** * One entry in a batch-approval prompt. Mirrors the device library's * `RequestApprovalOptions` — the engine previously passed its own internal struct here, * which carried none of the fields the connector actually reads. * * Deliberately narrow: this crosses a trust boundary into third-party connector code, so * it carries only what a user needs to approve. No notes, no UTXOs, and above all no key * material — the engine holds the viewing private key for a hardware wallet, and handing * that to a connector would expose the wallet's entire transaction history. */ export type BatchApprovalRequest = { readonly id: string; readonly description: string; readonly publicInputs: PublicInputsRailgun; readonly hash: bigint; }; /** * What a connector returns from a batch-approval prompt. * * The device library resolves an object carrying the sub-session AND whether the user * actually approved; older connectors resolve the sub-session string directly, or only a * boolean. Accepting all three keeps the shipped `EngineLedgerConnector` assignable to this * type — it previously was not, since it returns `LedgerBatchApprovalSession` where this * demanded a string. * * The object and boolean forms matter for more than typing: a rejected batch resolves * rather than throws, so a host that only reads `subSession` would proceed with a batch * the user declined. `requestBatchApproval` below refuses that. */ export type BatchApprovalResult = string | boolean | { readonly approved: boolean; readonly subSession: string; }; export type ExternalSignerConnector = { sign: ExternalSignerConnectorSignFn; requestBatchApproval?: (requests: readonly BatchApprovalRequest[]) => Promise; }; /** The message a RAILGUN transact signs: poseidon over its public inputs. */ export declare const publicInputsHash: (publicInputs: PublicInputsRailgun) => bigint; declare class HardwareWallet extends RailgunWallet { private connector; private readonly storedSpendingPublicKey; private readonly railgunAccountIndex; /** * Route transacts through the Ledger clear-sign flow. Off by default. * * The connector exposes no capability surface — clear-sign support is advertised by the * device app profile (`capabilities.railgunClearSign`), which only the integrator can * see — so this flag is the integrator's assertion that the connected device supports * it. If that assertion is wrong the device simply returns no clear-sign data, and * `clearSignTransact` throws rather than falling back to host encryption. */ clearSignEnabled: boolean; /** * Narrow the shape envelope while clear-signing: the device builds and hashes the * transact itself, so its Poseidon arity caps it at 1-3 inputs, 1-3 outputs, n+m <= 5. * Blind signing is unaffected — the device only ever receives a 32-byte hash and never * sees the counts — so the default envelope stands there. */ get signingEnvelope(): SigningEnvelope; /** * How to choose between clear and blind signing per batch. Only consulted when * `clearSignEnabled` is true — the flag stays the integrator's assertion that the device * *can* clear-sign, and this decides whether it *should* for a given batch. */ clearSignMode: ClearSignMode; /** * Most transactions a batch may split into and still be worth clear-signing. Each * transaction costs the user one on-device review, so this is a UX ceiling, not a * safety one. Undefined means no ceiling. * * Only meaningful under `prefer`: it is what makes the fallback fire on the common case * (a wallet of small UTXOs) rather than only on the rare shape that cannot be split at * all. Under `require` it turns into a hard failure, which is what `require` means. */ clearSignMaxTransactions?: number; /** * Clear-sign first when the device can, blind second unless the caller forbade the * downgrade. Only shapes are decided here; whether a specific batch qualifies at all * (V2, no memo text) is the batch's own precheck, since it depends on the outputs. */ get signingAttempts(): readonly SigningAttempt[]; constructor(id: string, db: Database, viewingKeyPair: ViewingKeyPair, spendingPublicKey: SpendingPublicKey, creationBlockNumbers: Optional, prover: Prover, railgunAccountIndex: number); protected getEphemeralSignerAccountIndex(_encryptionKey: string): Promise; /** * The device provider is keyed by the engine's own stored index (getCurrentEphemeralSigner * passes it as `ephemeralIndex`), so a locked increment is well defined. Without a device * provider there is nothing to ratchet. History scanning stays refused: the engine cannot * rebuild device addresses from an index. */ protected ratchetsEphemeralIndex(provider: EphemeralSignerProvider): boolean; /** * A hardware wallet stores no mnemonic, so its RelayAdapt7702 ephemeral keys live on the * device and are reached only through a custom ephemeral signer provider. */ getEphemeralWallet(_encryptionKey: string, _chainId: bigint, _index: number, _mnemonicPassword?: string): Promise; getSpendingKeyPair(_encryptionKey: string): Promise; /** Spending public key the device signature must verify against. */ get clearSignSpendingPublicKey(): SpendingPublicKey; setConnector(connector: ExternalSignerConnector): void; requestBatchApproval(requests: readonly BatchApprovalRequest[]): Promise>; sign(publicInputs: PublicInputsRailgun, subSession: string): Promise; /** * Clear-sign one transact: the device reviews plaintext recipients/tokens/amounts, * chooses each output's randomness, and returns the signature alongside the output * ciphertexts it generated. * * Stateless by design — request in, everything out in one call. There is no "arm the * next sign" latch to mis-order across a batch, which would pair one transaction's * ciphertext with another's notes. * * Every guard here runs before the device is touched. The returned outputs are NOT yet * trusted: re-deriving and verifying them against the approved plaintext is the * caller's job, and it must happen before proof generation. */ clearSignTransact(txidVersion: TXIDVersion, publicInputs: PublicInputsRailgun, request: ClearSignTransactRequest, subSession: string): Promise; private static generateHardwareID; private static getHardwareViewingKeyPair; private static createHardwareWallet; /** * @param railgunAccountIndex - device account the shareable viewing key was read from; * RelayAdapt7702 ephemeral keys are derived under the same account. Required on first * create; a re-create may omit it and keeps the stored account. */ static fromShareableViewingKey(db: Database, encryptionKey: string, shareableViewingKey: string, creationBlockNumbers: Optional, prover: Prover, requestedRailgunAccountIndex?: number): Promise; private static readStoredRailgunAccountIndex; static loadExisting(db: Database, encryptionKey: string, id: string, prover: Prover): Promise; } export { HardwareWallet };