# @varan-wallet/varan-connect A lightweight TypeScript library for Telegram Web App wallet integration with support for both CommonJS and ES modules. ## Installation ```bash npm install @varan-wallet/varan-connect # or pnpm add @varan-wallet/varan-connect # or yarn add @varan-wallet/varan-connect ``` ## Usage ### ES Modules (Recommended) ```typescript import { injectVaranWallet } from '@varan-wallet/varan-connect'; import WebApp from '@twa-dev/sdk'; // Inject the Varan wallet into the window object injectVaranWallet(WebApp); // The wallet is now available at window.injectedWeb3.varan const varanWallet = window.injectedWeb3?.varan; if (varanWallet) { // Connect to wallet const connection = await varanWallet.connect(); // Get accounts const accounts = await connection.accounts.get(); // Sign transactions const signer = connection.signer; const signature = await signer.signRaw({ address: '0x123...', data: '0x456...' }); } ``` ### CommonJS ```javascript const { injectVaranWallet } = require('@varan-wallet/varan-connect'); const WebApp = require('@twa-dev/sdk').default; // Inject the Varan wallet injectVaranWallet(WebApp); // Use the injected wallet const varanWallet = window.injectedWeb3?.varan; ``` ## Module Support This library supports both module systems: - **ES Modules (ESM)**: Modern JavaScript modules using `import`/`export` - **CommonJS (CJS)**: Node.js traditional modules using `require`/`module.exports` The library automatically detects which module system you're using and provides the appropriate format. ## API ### `injectVaranWallet(webApp: WebApp): void` Injects the Varan wallet into the window object for Telegram Web App integration. **Parameters:** - `webApp`: The Telegram Web App instance from `@twa-dev/sdk` **Returns:** `void` ## Types The library exports comprehensive TypeScript types: - `WebApp` - Telegram Web App interface from `@twa-dev/sdk` - `InjectedWindow` - Extended window interface with injected wallet from `@polkadot/extension-inject` - `ConnectRequest`, `SignTransactionRequest` - Request interfaces - `ConnectResult`, `SignTransactionResult` - Result interfaces - `InjectionConfig` - Configuration options for wallet injection ## Dependencies **Runtime Dependencies:** - `@twa-dev/sdk` - Telegram Web App SDK **Development Dependencies:** - `@polkadot/extension-inject` - Polkadot extension injection types - `@polkadot/types` - Polkadot types - TypeScript for compilation - ESLint for code quality - Prettier for code formatting - Jest for testing ## Build Outputs The library provides multiple build outputs: - `dist/esm/` - ES Modules build (`.mjs` compatible) - `dist/cjs/` - CommonJS build (Node.js compatible) - `dist/types/` - TypeScript type definitions ## Development ### Setup ```bash pnpm install ``` ### Build ```bash pnpm run build # Build all formats pnpm run build:esm # Build ES modules only pnpm run build:cjs # Build CommonJS only pnpm run build:types # Build types only ``` ### Development mode ```bash pnpm run dev ``` ### Testing ```bash pnpm test ``` ### Linting ```bash pnpm run lint ``` ### Formatting ```bash pnpm run format ``` ### Publishing ```bash # Publish with automatic version bumping pnpm run publish:patch # 1.0.0 -> 1.0.1 pnpm run publish:minor # 1.0.0 -> 1.1.0 pnpm run publish:major # 1.0.0 -> 2.0.0 # Manual publish (after building) pnpm publish ``` ## License MIT