@bitslab-nexauth/wallet-sdk
v1.2.0
Published
Embedded wallet SDK logic core
Downloads
1,127
Readme
@nexauth/wallet-sdk
Embedded Wallet SDK for secure, seamless wallet integration.
Features
- Embedded Iframe Architecture: Securely isolates wallet keys and signing logic within an iframe.
- Multi-Chain Support: Supports EVM (ETH, BSC, Polygon), Sui, Aptos, Solana, and BTC.
- Authentication: Built-in support for social login (Google, Twitter, GitHub, etc.) and email auth.
- MFA Support: Integrated 2FA enrollment and verification flows.
- Transaction Signing: Secure transaction signing for EVM and Sui chains.
- Headless Mode: Customizable UI with headless login capabilities.
Installation
npm install @nexauth/wallet-sdkUsage
1. Initialize SDK
import { MyWalletSDK } from "@nexauth/wallet-sdk";
// Initialize with your App ID
const sdk = new MyWalletSDK("your-app-id");2. Subscribe to State Changes
sdk.subscribe((state) => {
console.log("SDK State:", state);
// state.ready: boolean - SDK is ready
// state.authenticated: boolean - User is logged in
// state.user: AuthResult | null - User information
});3. Login
Default Modal Login
try {
const user = await sdk.login();
console.log("Logged in user:", user);
} catch (error) {
console.error("Login failed:", error);
}Headless Social Login
// Provider: 'google' | 'twitter' | 'github' | 'line' | 'telegram' | 'apple'
const user = await sdk.loginWith('google');4. Wallet Operations
Create Wallet
const result = await sdk.createWallet(['ETH', 'SUI']);Get Wallet Addresses
const addresses = await sdk.getAddress(['ETH', 'SUI']);
console.log(addresses); // { ETH: "0x...", SUI: "0x..." }Get User Info (Silent)
const user = await sdk.getUser();5. Transaction Signing
Sign Transaction
const txHash = await sdk.signTransaction({
to: "0x...",
value: "0.1",
data: "0x...",
chainId: 1
});Build Transaction
const signedTx = await sdk.buildTransaction({
chainType: 'evm',
from: "0x...",
params: {
to: "0x...",
value: "1000000000"
}
});6. MFA (Multi-Factor Authentication)
// Enroll MFA
await sdk.enrollMFA();
// Close MFA Flow
await sdk.closeMFA();7. Logout
await sdk.logout();Types
AuthResult
interface AuthResult {
address: string;
email?: string;
token: string;
provider: string;
isNewUser: boolean;
}ChainType
"SUI" | "EVM" | "BSC" | "POLYGON" | "APTOS" | "SOLANA" | "BTC"
Error Handling
The SDK returns Promises that reject with an error object containing code and message when operations fail or are cancelled by the user.
try {
await sdk.login();
} catch (error) {
if (error.code === 4001) {
console.log("User rejected the request");
} else if (error.code === -32002) {
console.log("Request already in progress");
} else if (error.code === -32603) {
console.log("Request timed out");
}
}