createCloak, so the same login gives the user
a private balance. External wallets connected through Privy work the same way.
Tested against @privy-io/react-auth 3.52.1 and @cloak.dev/sdk 0.2.20.
How it works
The embedded wallet is an ordinary ed25519 key held by Privy, so it signs the account message the same
way every time.
createCloak checks that on first use by signing twice and comparing, and refuses a
wallet whose signatures differ instead of silently opening a different account.
Privy smart wallets are not Solana wallets. Privy’s smart wallets are ERC-4337 accounts on EVM
chains. Use the embedded Solana wallet for Cloak. See Smart wallets.
Prerequisites
- A Privy app with Solana embedded wallets enabled. Copy its App ID.
- A Next.js (App Router) or React app.
- A mainnet RPC URL and its WebSocket URL.
@stripe/stripe-js is needed by a Privy module that webpack (the Next.js default bundler) resolves at
build time.
.env.local
1. Configure the Privy provider
Create Solana embedded wallets at login and give Privy a mainnet RPC. Privy’s Solana wallet hooks need thesolana.rpcs entry.
app/providers.tsx
<Providers>.
2. Get the embedded wallet
useWallets() from @privy-io/react-auth/solana returns ConnectedStandardSolanaWallet objects.
Pass one to createCloak as it is. The SDK recognizes it and drives the wallet’s standard
solana:signMessage and solana:signTransaction features.
3. Open the Cloak account
Keep the opened account in React state. Open it after an explicit user action, because it asks the wallet to sign.hooks/use-cloak.ts
cloak.address is the user’s cloak_ address. The same Privy login opens the same Cloak account on
any device, because the account comes from the wallet’s signature.
4. Shield, send and withdraw
components/private-balance.tsx
What the user sees
- Signature prompts. Whether Privy shows its own confirmation for each signature follows your
embeddedWallets.showWalletUIssetting, or the dashboard’s when unset. - First open. Two signatures of the Cloak account message, then the address appears.
- Proof time. Each shield, send and withdrawal generates a zero-knowledge proof in the browser.
The first one also downloads about 23 MB of circuit files. Show
onProgresstext, and warm the circuits on mount withverifyAllCircuits(getCircuitsPath()).
Funding the embedded wallet
A new embedded wallet is empty. A shield from Solana needs the token plus a little SOL for the network fee, paid by the wallet. Two ways around that:- Shield from another chain. If the user holds USDC on Base or Polygon in an EVM wallet, pass that
wallet too and call
shield({ from: "base", ... }). The Solana side needs no SOL. See EVM wallets. - Sponsor the deposit with the low-level API’s
externalFeePayer. See Custom signers.
Server-side Privy wallets
A Privy server wallet is a@solana/kit signer from createSolanaKitSigner in @privy-io/node.
createCloak accepts it as a wallet and ignores its ability to send. See
Custom signers.
Troubleshooting
Related
- Privy example app: the complete Next.js project.
- createCloak: every call and receipt.
- Wallet integrations: how other wallet types compare.