@zaiffer/sdk
v0.1.3
Published
SDK for encrypted tokens on FHEVM using Zama's fhEVM technology
Maintainers
Readme
Zaiffer SDK
TypeScript SDK for building encrypted token applications on FHEVM (Fully Homomorphic Encryption).
Features
- 🔐 Encrypted Token Operations - Wrap, unwrap, and transfer tokens with full privacy
- ⚛️ React Integration - Ready-to-use hooks for React applications
- 🔧 Type-Safe - Full TypeScript support with comprehensive type definitions
- 🚀 Developer Friendly - Simple, intuitive API with great DX
- 🧪 Well Tested - 760+ tests ensuring reliability
- 📦 Modular - Use only what you need with tree-shakeable exports
Documentation
Comprehensive documentation is available in the docs/ directory:
- Getting Started - Installation, setup, and first steps
- Core Functions - Complete API reference for all core functions
- React Hooks - React integration guide with hooks documentation
- API Reference - Complete type definitions and interfaces
- Examples - Real-world examples and patterns
- Troubleshooting - Common issues and solutions
Quick Start
Installation
npm install zaiffer-sdk viem wagmiNode.js Usage
import { initializeSDK, wrapToken } from "zaiffer-sdk";
import { createWalletClient, createPublicClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
// Initialize the SDK
initializeSDK({ network: "sepolia" });
// Create clients
const account = privateKeyToAccount("0x...");
const publicClient = createPublicClient({
transport: http("https://rpc-url"),
});
const walletClient = createWalletClient({
account,
transport: http("https://rpc-url"),
});
// Wrap tokens
const txHash = await wrapToken({
client: walletClient,
publicClient,
wrapperAddress: "0x...",
amount: 1000000n,
to: account.address,
});React Usage
import { ZaifferProvider, useWrapToken } from "zaiffer-sdk/react";
import { WagmiProvider, createConfig, http } from "wagmi";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { sepolia } from "wagmi/chains";
// Configure Wagmi and React Query
const wagmiConfig = createConfig({
chains: [sepolia],
transports: { [sepolia.id]: http() },
});
const queryClient = new QueryClient();
function App() {
return (
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<ZaifferProvider network="sepolia">
<TokenManager />
</ZaifferProvider>
</QueryClientProvider>
</WagmiProvider>
);
}
function TokenManager() {
const { wrapToken, isLoading } = useWrapToken({
wrapper: "0x...",
encryptedToken: "0x...",
});
return (
<button onClick={() => wrapToken(1000000n)} disabled={isLoading}>
{isLoading ? "Wrapping..." : "Wrap Tokens"}
</button>
);
}Package Structure
The SDK is published with two main exports:
// Core SDK - Node.js and general use
import { initializeSDK, wrapToken, unwrapToken } from "zaiffer-sdk";
// React adapters - React-specific hooks and components
import { ZaifferProvider, useWrapToken, useUnwrap } from "zaiffer-sdk/react";Core API
SDK Configuration
initializeSDK({ network: "mainnet" | "sepolia" });Token Operations
// Wrap native tokens to encrypted tokens
wrapToken({ client, publicClient, wrapperAddress, amount, to });
// Unwrap encrypted tokens back to native tokens
unwrapToken({
client,
publicClient,
encryptedTokenAddress,
wrapperAddress,
from,
to,
handle,
inputProof,
});
// Finalize unwrap with decryption proof
finalizeUnwrap({
client,
publicClient,
wrapperAddress,
requestId,
abiEncodedClearBurnAmounts,
decryptionProof,
});
// Get encrypted balance
getEncryptedBalance({ client, encryptedTokenAddress, address });FHEVM Operations
// Create FHEVM instance for encryption/decryption
const instance = await createFhevmInstance("sepolia");
// Encrypt values
const { handles, inputProof } = await encryptValues(contractAddress, [
100n,
200n,
]);
// Decrypt handles
const results = await decryptHandles(
instance,
handles,
userAddress,
signature,
eip712Data
);React Hooks
// Token operations
const { wrapToken, isLoading } = useWrapToken({ wrapper, encryptedToken });
const { unwrap } = useUnwrap({ wrapper, encryptedToken });
const { finalizeUnwrap } = useFinalizeUnwrap({ wrapper });
// Query hooks
const { balance } = useGetEncryptedBalance({ encryptedToken, userAddress });
// FHEVM operations
const instance = useFhevmInstance();
const { encrypt } = useEncryptValues();
const { decrypt } = useDecryptHandles();License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Version: 0.1.0 Status: Active Development
