> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloak.ag/llms.txt
> Use this file to discover all available pages before exploring further.

# Hardware wallets

> Ledger and Trezor sign transactions but not arbitrary messages: how to use them with Cloak

Hardware wallets such as Ledger and Trezor usually sign Solana transactions but not arbitrary
messages. That one gap decides how they fit.

| Action | With a hardware wallet |
| - | - |
| Open a `createCloak` account by signature | Not possible: it needs a message signature |
| Shield from Solana | Yes: one transaction |
| Private send, withdrawal (with `createCloak`) | Yes, once the account is open: no wallet prompt |
| Private send, withdrawal (low-level API) | Yes: the wallet signs a 0 SOL self-transfer that is never sent |

## With `createCloak`: open the account another way

Pass the hardware wallet together with a way to open the account. The wallet is then used for
shields only.

```ts theme={null}
import { createCloak } from "@cloak.dev/sdk";

declare const ledgerWallet: unknown; // the wallet-adapter context or adapter for the Ledger

// Option A: the user's Cloak Key (24 words from cloak.ag). The Ledger is linked to it.
const cloak = await createCloak({
  wallet: ledgerWallet,
  cloakKey: process.env.CLOAK_KEY_WORDS!, // from user input in a real app, never an env var in a browser
  rpc: process.env.SOLANA_RPC_URL,
});

await cloak.shield({ from: "solana", token: "USDC", amount: "10" }); // the Ledger signs this
```

You can also pass the hardware wallet together with a second wallet that signs messages
(`wallets: [phantom, ledger]`): the second one opens the account. Passing only a hardware wallet
throws `account.no_signer`.

A Ledger behind a legacy wallet adapter receives a web3.js `VersionedTransaction`. In a bundled app
pass the class in: `createCloak({ ..., web3: { VersionedTransaction } })`.

## With the low-level API

Pass `signer` and leave `signMessage` out. Every submitted request is then authenticated by asking
the wallet to sign a deterministic legacy transaction: a 0-lamport transfer to itself whose blockhash
field carries the request digest. It can never land on chain and is never sent.

```ts theme={null}
import { VersionedTransaction } from "@solana/web3.js";
import { signerFromWalletAdapter, type LegacyWalletAdapter } from "@cloak.dev/sdk";

export function hardwareSigner(adapter: LegacyWalletAdapter) {
  // No signMessage: the SDK falls back to the self-transfer authentication.
  return signerFromWalletAdapter(adapter, { web3: { VersionedTransaction } });
}
```

> [!WARNING]
>
> Tell the user what they are approving. The device shows a 0 SOL transfer to the user's own
> address. Explain before the prompt that it is an authentication, not a payment, or users will reject
> it.

Give a hardware wallet `signer` or `signMessage`, never both: when both are present the SDK uses
`signMessage`, which a Ledger cannot do. A request stays valid for 300 seconds and its clock
starts before the device prompt, so a slow confirmation on the device can expire it. See
[Request authentication](https://docs.cloak.ag/sdk/request-authentication.md#hardware-wallet-signer-instead-of-signmessage).

## Wallets that change what they sign

Some wallets add compute-budget or guard instructions to the authentication transaction before the
device signs it. The SDK accepts those additions only for the ComputeBudget and Lighthouse programs,
and verifies the signature over the changed message before sending it on.

## Related

* [Solana wallet adapter](https://docs.cloak.ag/wallets/wallet-adapter.md)
* [Request authentication](https://docs.cloak.ag/sdk/request-authentication.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.