TypeScript Quickstart
Get started with Privacy Boost in TypeScript in 5 minutes.Installation
Copy
npm install @testinprod-io/privacy-boost
# or
yarn add @testinprod-io/privacy-boost
# or
pnpm add @testinprod-io/privacy-boost
Quick Example
Copy
import { PrivacyBoost, Eip1193WalletAdapter } from '@testinprod-io/privacy-boost';
// 1. Initialize SDK
const sdk = await PrivacyBoost.create({
indexerUrl: 'https://test-api.privacy-boost.sunnyside.io/indexer',
proverUrl: 'https://test-api.privacy-boost.sunnyside.io/prover',
chainId: 11155420,
shieldContract: "0xB22fD661b322F10d4B7cd0cFcb9578C485423119",
wethContract: "0x4200000000000000000000000000000000000006"
});
// 2. Connect wallet (using browser's window.ethereum)
const adapter = new Eip1193WalletAdapter(window.ethereum);
await sdk.auth.connect(adapter);
// 3. Login (derive privacy keys)
const { privacyAddress } = await sdk.auth.login();
console.log('Your privacy address:', privacyAddress);
// 4. Check balance
const balance = await sdk.vault.getBalance('0x...token-address');
console.log('Shielded balance:', balance);
// 5. Deposit tokens
const depositResult = await sdk.vault.deposit({
tokenAddress: '0x...token-address',
amount: 1000000000000000000n, // 1 token (18 decimals)
});
console.log('Deposit tx:', depositResult.txHash);
// 6. Send privately
const sendResult = await sdk.vault.send({
to: recipientPrivacyAddress,
tokenAddress: '0x...token-address',
amount: 500000000000000000n,
});
console.log('Transfer tx:', sendResult.txHash);
// 7. Withdraw to any address
const withdrawResult = await sdk.vault.withdraw({
tokenAddress: '0x...token-address',
amount: 250000000000000000n,
recipientAddress: '0x...recipient-address',
});
console.log('Withdraw tx:', withdrawResult.txHash);
Progress Tracking
Track operation progress with callbacks:Copy
await sdk.vault.deposit({
tokenAddress: '0x...',
amount: 1000000000000000000n,
onProgress: ({ step, message, txHash }) => {
console.log(`Step: ${step}, Message: ${message}`);
if (txHash) console.log(`Tx: ${txHash}`);
},
});
Session Persistence
Save and restore sessions:Copy
// Export session
const session = sdk.auth.exportSession();
localStorage.setItem('privacy_session', JSON.stringify(session));
// Restore session later
const savedSession = JSON.parse(localStorage.getItem('privacy_session'));
await sdk.auth.importSession(savedSession);