1.0.5 • Published 6 months ago
@onoal/wallet v1.0.5
Onoal Wallet SDK
A TypeScript SDK for creating and managing multi-chain wallets with OAuth integration.
Installation
npm install @onoal/wallet @onoal/core @onoal/auth
Configuration
Ensure you have an onoal.json file in your project root, provided by @onoal/core:
{
"chain": {
"solana": { "net": "mainnet" },
"ethereum": { "net": "mainnet" },
"bitcoin": { "net": "mainnet" },
"xrpl": { "net": "mainnet" },
"sui": { "net": "mainnet" },
"cosmos": {
"osmosis": { "net": "custom", "custom": "https://rpc.custom.osmosis.com" }
}
},
"api": {
"url": "https://api.onoal.com",
"key": "your-test-api-key"
},
"auth": {
"clientIds": {
"google": "your-google-client-id",
"twitter": "your-twitter-client-id",
"discord": "your-discord-client-id"
},
"redirectUri": "https://your-app.com/callback",
"mpcNetwork": "https://mpc.onoal.com"
}
}
Usage
import { WalletClient } from '@onoal/wallet';
import { AuthClient } from '@onoal/auth';
import { loadConfig } from '@onoal/core';
// Initialize with configuration
const config = loadConfig();
const wallet = new WalletClient(config);
const auth = new AuthClient(config);
// Create a single-chain wallet
const solanaWallet = await wallet.createWallet({ chain: 'solana' });
console.log('Solana Wallet:', solanaWallet);
// Create a multi-chain wallet
const multiWallet = await wallet.createMultiChainWallet({
chains: ['solana', 'ethereum', 'bitcoin', 'xrpl', 'sui', 'cosmos'],
});
console.log('Multi-Chain Wallet:', multiWallet);
// Create a wallet from OAuth
const loginUrl = await auth.login({ provider: 'google' });
window.location.href = loginUrl; // Redirect to Google login
// After callback:
const user = await auth.verifyOAuthCallback('google', new URLSearchParams(window.location.search).get('code'));
const oauthWallet = await wallet.generateWalletFromOAuth(user);
console.log('OAuth Wallet:', oauthWallet);
// Import a wallet from mnemonic
const importedWallet = await wallet.importWalletFromMnemonic(
'word1 word2 ... word12',
'bitcoin'
);
console.log('Imported Wallet:', importedWallet);
// Get balance
const balance = await wallet.getBalance(solanaWallet);
console.log('Balance:', balance);