cryptoauthsso-sdk
v1.0.0
Published
Universal TypeScript SDK for CryptoAuthSSO
Maintainers
Readme
@cryptoauthsso/sdk
Universal TypeScript SDK for CryptoAuthSSO - Secure wallet authentication with email verification.
Installation
npm install @cryptoauthsso/sdk
# or
yarn add @cryptoauthsso/sdkQuick Start
import { CryptoAuthSSO } from '@cryptoauthsso/sdk';
// Initialize with your API key
const cryptoGate = new CryptoAuthSSO({
apiKey: 'your-api-key',
baseUrl: 'https://api.cryptogate.dev' // optional, defaults to production
});
// Send verification code
await cryptoGate.auth.sendCode('[email protected]');
// Verify code and authenticate
const session = await cryptoGate.auth.verifyCode('[email protected]', '123456');
// Set session for wallet operations
cryptoGate.setSessionToken(session.session.token);
// Create a new wallet
const wallet = await cryptoGate.wallets.create('My Wallet');
// List wallets
const wallets = await cryptoGate.wallets.list();
// Sign a message
const signature = await cryptoGate.wallets.sign(wallet.wallet.id, 'Hello World');Features
- 🔐 Email-based authentication - No passwords required
- 🎯 Universal compatibility - Works with React, Next.js, Vue, vanilla JS
- 💼 Full wallet management - Create, list, sign, send transactions
- 🔒 Secure by default - Encrypted storage and secure session management
- 📱 Modern TypeScript - Full type definitions included
Authentication
Send Verification Code
const response = await cryptoGate.auth.sendCode('[email protected]');
console.log(response.message); // "Verification code sent"Verify Code
const authResponse = await cryptoGate.auth.verifyCode('[email protected]', '123456');
console.log(authResponse.user); // User object
console.log(authResponse.session); // Session with tokenSet Session Token
// Required for wallet operations
cryptoGate.setSessionToken(authResponse.session.token);Wallet Management
Create Wallet
const response = await cryptoGate.wallets.create('My Ethereum Wallet', 'ethereum');
console.log(response.wallet.address); // 0x1234...List Wallets
const response = await cryptoGate.wallets.list();
console.log(response.wallets); // Array of wallet objectsSign Message
const response = await cryptoGate.wallets.sign(walletId, 'Message to sign');
console.log(response.signature); // Cryptographic signatureSend Transaction
const response = await cryptoGate.wallets.send(
walletId,
'0xrecipient...',
'0.1', // ETH amount
{ gasLimit: 21000 }
);
console.log(response.transaction.txHash);User Management
Get User Profile
const response = await cryptoGate.wallets.getProfile();
console.log(response.user); // User profile with wallet countGet User Sessions
const response = await cryptoGate.wallets.getSessions();
console.log(response.sessions); // Active sessionsError Handling
try {
await cryptoGate.auth.sendCode('invalid-email');
} catch (error) {
if (error.status === 400) {
console.log('Invalid email format');
}
console.log(error.message); // Error description
}Framework Examples
React
import { useState } from 'react';
import { CryptoAuthSSO } from '@cryptoauthsso/sdk';
const cryptoGate = new CryptoAuthSSO({ apiKey: 'your-key' });
function Login() {
const [email, setEmail] = useState('');
const [code, setCode] = useState('');
const [step, setStep] = useState('email');
const sendCode = async () => {
await cryptoGate.auth.sendCode(email);
setStep('verify');
};
const verifyCode = async () => {
const session = await cryptoGate.auth.verifyCode(email, code);
cryptoGate.setSessionToken(session.session.token);
// User is now authenticated
};
return (
<div>
{step === 'email' ? (
<div>
<input value={email} onChange={(e) => setEmail(e.target.value)} />
<button onClick={sendCode}>Send Code</button>
</div>
) : (
<div>
<input value={code} onChange={(e) => setCode(e.target.value)} />
<button onClick={verifyCode}>Verify</button>
</div>
)}
</div>
);
}Next.js
// pages/api/auth/verify.ts
import { CryptoAuthSSO } from '@cryptoauthsso/sdk';
export default async function handler(req, res) {
const cryptoGate = new CryptoAuthSSO({
apiKey: process.env.CRYPTOGATE_API_KEY
});
const { email, code } = req.body;
try {
const session = await cryptoGate.auth.verifyCode(email, code);
res.json(session);
} catch (error) {
res.status(400).json({ error: error.message });
}
}Configuration
const cryptoGate = new CryptoAuthSSO({
apiKey: 'your-api-key', // Required: Your CryptoAuthSSO API key
baseUrl: 'https://api.custom.com' // Optional: Custom API endpoint
});License
MIT © CryptoAuthSSO Team
