/// import { Signature } from '@railgun-community/circomlibjs'; import { TXIDVersion } from '../models/poi-types'; /** * Ledger CLEAR_SIGN transact contract — declared here, imported from nowhere. * * These types are structurally identical to the ones `@railgun-community/ledger-client` * exports, and TypeScript's structural typing is what makes its connector satisfy * `ExternalSignerConnector` without either package importing the other. That is * deliberate and must stay that way: * * - the engine is CommonJS (`module: commonjs`), ledger-client is ESM-only * (`"type": "module"`, and its `exports` map exposes only an `import` condition), * so a real import would not resolve; * - ledger-client already models engine concepts (`PublicInputsRailgun`, `Signature`) * and injects itself via `setConnector`, so importing it back closes a cycle; * - the engine stays device-agnostic — a second hardware vendor must not require * engine changes. * * Everything the engine sees is DECODED. Raw device bytes and the 208-byte OUT_* tuple * layout stay inside the device library, which owns the wire format and its vectors. */ export declare const CLEAR_SIGN_MIN_INPUTS = 1; export declare const CLEAR_SIGN_MAX_INPUTS = 3; export declare const CLEAR_SIGN_MIN_OUTPUTS = 1; export declare const CLEAR_SIGN_MAX_OUTPUTS = 3; export declare const CLEAR_SIGN_MAX_INPUTS_PLUS_OUTPUTS = 5; /** * How a hardware wallet should choose between clear and blind signing, per batch. * * Clear-signing is shape-limited — 1-3 inputs, 1-3 outputs, `n + m <= 5`, V2 only, no memo * text. Blind signing has none of those limits: the device receives a 32-byte hash and * never sees the transaction, so it covers effectively every circuit. A device that can * clear-sign can always also blind-sign, so the two are not mutually exclusive * capabilities — they are a per-batch choice. * * - `prefer` (default): clear-sign when the batch qualifies and the clear envelope can * satisfy it; otherwise fall back to blind. This is what an app wants by default — * the user gets on-device review whenever it is possible, and sends never fail merely * because a shape is out of range. * - `require`: clear-sign or fail. For flows where an unreviewed signature is not an * acceptable outcome, and a hard error is preferable to a silent downgrade. * - `never`: blind-sign, even though the device could clear-sign. * * `prefer` downgrades silently by design. If a caller must know which mode was actually * used, it should use `require` and handle the error, or read the batch result. */ export type ClearSignMode = 'require' | 'prefer' | 'never'; export declare const CLEAR_SIGN_DEFAULT_MODE: ClearSignMode; /** Device caps a transfer memo at 32 bytes; engine `memoText` has no such limit. */ export declare const CLEAR_SIGN_MAX_MEMO_BYTES = 32; /** Decoded OUT_* field widths — consumed by the checks in `transaction/clear-sign-verify`. */ export declare const CLEAR_SIGN_BYTES_RANDOM = 16; export declare const CLEAR_SIGN_BYTES_BLINDING_KEY = 32; export declare const CLEAR_SIGN_BYTES_IV = 16; export declare const CLEAR_SIGN_BYTES_TAG = 16; export declare const CLEAR_SIGN_BYTES_CIPHERTEXT = 96; export declare const CLEAR_SIGN_BYTES_SENDER_RANDOM = 15; export declare const CLEAR_SIGN_BYTES_ANNOTATION_IV = 16; export declare const CLEAR_SIGN_BYTES_WALLET_SOURCE = 15; export declare const CLEAR_SIGN_BYTES_COMMITMENT = 32; export type ClearSignBpFields = { readonly treeNumber: number; /** uint48 — the device rejects anything wider. */ readonly minGasPrice: bigint; readonly unshield: boolean; /** uint64 */ readonly chainId: bigint; /** 20 bytes; omit for a plain (non-adapt) transact. */ readonly adaptContract?: Uint8Array; /** 32 bytes; omit for a plain (non-adapt) transact. */ readonly adaptParams?: Uint8Array; }; export type ClearSignBroadcasterOutput = { readonly kind: 'broadcaster'; readonly recipientMasterPublicKey: Uint8Array; readonly recipientViewingPublicKey: Uint8Array; readonly tokenHash: Uint8Array; readonly value: bigint; }; export type ClearSignChangeOutput = { readonly kind: 'change'; readonly tokenHash: Uint8Array; readonly value: bigint; }; export type ClearSignTransferOutput = { readonly kind: 'transfer'; /** 127-character bech32m `0zk1…` address. */ readonly recipient0zk: string; readonly tokenHash: Uint8Array; readonly value: bigint; readonly outputType?: number; readonly memo?: Uint8Array; }; export type ClearSignUnshieldOutput = { readonly kind: 'unshield'; /** 20-byte EVM address. */ readonly recipientAddress: Uint8Array; readonly tokenHash: Uint8Array; readonly value: bigint; }; export type ClearSignOutput = ClearSignBroadcasterOutput | ClearSignChangeOutput | ClearSignTransferOutput | ClearSignUnshieldOutput; export type ClearSignOutputKind = ClearSignOutput['kind']; export type ClearSignTransactRequest = { readonly account?: number; readonly merkleRoot: Uint8Array; readonly nullifiers: readonly Uint8Array[]; readonly boundParams: ClearSignBpFields; /** Canonical order: broadcaster -> change -> (transfer | unshield). */ readonly outputs: readonly ClearSignOutput[]; /** * 15-byte wallet-source tag the device encrypts into each transfer's annotation data, * which is part of the hash it signs. Without it the device uses 15 zero bytes. */ readonly walletSource?: Uint8Array; }; /** * A device-generated output note. The device chose `random`/`senderRandom` and produced * the ciphertext, so every field here is untrusted input until `transaction/clear-sign-verify` * re-derives it — nothing in this module treats it as authoritative. */ export type ClearSignDecodedNoteOutput = { readonly kind: 'broadcaster' | 'change' | 'transfer'; readonly random: Uint8Array; /** Blind1 */ readonly senderBlindingKey: Uint8Array; /** Blind2 */ readonly recipientBlindingKey: Uint8Array; readonly iv: Uint8Array; readonly tag: Uint8Array; readonly ciphertext: Uint8Array; readonly senderRandom: Uint8Array; /** Returned for `transfer` only, to rebuild their annotation data. */ readonly annotationIv?: Uint8Array; }; export type ClearSignDecodedUnshieldOutput = { readonly kind: 'unshield'; readonly commitment: Uint8Array; }; export type ClearSignDecodedOutput = ClearSignDecodedNoteOutput | ClearSignDecodedUnshieldOutput; /** Raw device response for one output, exactly as the connector hands it back. */ export type ClearSignOutputResult = { readonly kind: ClearSignOutputKind; readonly response: Uint8Array; }; /** * A signature as a connector hands it back. Device libraries type the point as a readonly * tuple (`@railgun-community/ledger-client` does), which a mutable `Signature` would * reject, so the seam accepts both. Normalize with `connectorSignatureToSignature`. */ export type ConnectorSignature = { readonly R8: readonly [bigint, bigint]; readonly S: bigint; }; /** Copy a connector signature into an engine `Signature`, dropping any other fields. */ export declare const connectorSignatureToSignature: (signature: ConnectorSignature) => Signature; /** * What the connector's `sign` resolves to: a signature, plus `clearSign` only when a * request was supplied. */ export type ClearSignConnectorResult = ConnectorSignature & { readonly clearSign?: { readonly msgHash: Uint8Array; readonly outputs: readonly ClearSignOutputResult[]; }; }; /** Engine-facing result: same data, outputs decoded. */ export type ClearSignResult = { readonly signature: Signature; /** The message the device signed. Never adopt it — recompute and compare. */ readonly msgHash: Uint8Array; /** Index-aligned with the request's outputs. */ readonly outputs: readonly ClearSignDecodedOutput[]; }; /** * Device response lengths. `broadcaster`/`change` carry the 208-byte tuple plus * `senderRandom`; `transfer` adds `annotationIv`; `unshield` is just its commitment. */ export declare const CLEAR_SIGN_RESPONSE_BYTES_NOTE = 223; export declare const CLEAR_SIGN_RESPONSE_BYTES_TRANSFER = 239; export declare const CLEAR_SIGN_RESPONSE_BYTES_UNSHIELD = 32; /** * Decode one raw OUT_* response. * * tuple(208) = random(16) || Blind1(32) || Blind2(32) || IV(16) || tag(16) || ct(96) * + senderRandom(15) [+ annotationIv(16) for transfer]; unshield = commitment(32) * * This mirrors `decodeClearSignOutput` in `@railgun-community/ledger-client`, which the * engine cannot call: it is a value export from an ESM-only package whose `exports` map * has no `require` condition, and the engine is CommonJS. Types can still be shared by * structure (they are erased), but this function has to exist here. * * The layout is firmware-pinned (1.6.1 clear-sign-v1). If it ever drifts, the output * verification catches it immediately and loudly — wrong offsets mean the blinded keys * will not recompute and the ciphertext will not decrypt — so this never silently * produces a wrong commitment. */ export declare const decodeClearSignOutput: (result: ClearSignOutputResult) => ClearSignDecodedOutput; /** * Device Poseidon arity cap. The engine permits up to 5 outputs and many more inputs, so * a clear-sign wallet must have its spending solutions constrained to this envelope * before a batch is built. */ export declare const assertClearSignShape: (nIn: number, nOut: number) => void; /** Only V2 is implemented. V3 must never silently fall through to host encryption. */ export declare const assertClearSignTxidVersion: (txidVersion: TXIDVersion) => void; /** Full structural validation of a request, before any device round-trip. */ export declare const assertClearSignRequest: (request: ClearSignTransactRequest) => void; /** * The device response must line up 1:1 with the request. A connector that drops * `outputs`, returns too few, or permutes kinds would otherwise mis-pair ciphertext with * notes downstream — which produces an on-chain commitment the recipient can never * decrypt. Fail closed here rather than discover it during proof generation. */ export declare const assertClearSignOutputsAligned: (request: ClearSignTransactRequest, outputs: readonly { readonly kind: ClearSignOutputKind; }[]) => void; /** * Validate a raw connector result and decode it. A connector that ignored the clear-sign * argument returns a bare `Signature` with no `clearSign` — that must fail loudly rather * than fall through to host encryption against a device signature over different * boundParams. */ export declare const decodeClearSignConnectorResult: (request: ClearSignTransactRequest, result: ClearSignConnectorResult) => ClearSignResult;