@varity-labs/client-js 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,31 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Varity Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Varity SDK - Web3 Operating System
26
+
27
+ Build and deploy apps on Varity L3 with 70-85% cost savings vs traditional cloud.
28
+
29
+ For more information, visit https://varity.so
30
+
31
+ "Powered by Varity" attribution is required when using this SDK.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @varity/client-js
2
+
3
+ > Comprehensive JavaScript/TypeScript SDK for Varity L3 Blockchain - Powered by Thirdweb v5.112.0
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@varity/client-js.svg)](https://www.npmjs.com/package/@varity/client-js)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Overview
9
+
10
+ `@varity/client-js` is a complete SDK for building applications on Varity L3, an Arbitrum Orbit L3 blockchain with USDC as the native gas token. This library provides:
11
+
12
+ - 🔗 **Wallet Management** - Connect MetaMask, WalletConnect, Coinbase, and more
13
+ - 📝 **Smart Contract Interactions** - Read, write, deploy, and monitor contracts
14
+ - 🔐 **SIWE Authentication** - Sign-In with Ethereum (EIP-4361)
15
+ - 📦 **IPFS Storage** - Upload and download files via Thirdweb
16
+ - ⚛️ **React Hooks** - Easy integration with React applications
17
+ - 💰 **USDC Support** - Native 6-decimal USDC handling utilities
18
+ - 🌐 **Multi-Chain** - Support for Varity L3, Arbitrum Sepolia, and Arbitrum One
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install @varity/client-js thirdweb
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```typescript
29
+ import { VarityClient, formatUSDC } from '@varity/client-js';
30
+
31
+ // Initialize client
32
+ const client = new VarityClient({
33
+ clientId: 'your-thirdweb-client-id',
34
+ chain: 'varity-l3'
35
+ });
36
+
37
+ // Connect wallet
38
+ const account = await client.wallet.connect({ walletType: 'metamask' });
39
+ console.log('Connected:', account.address);
40
+
41
+ // Get balance
42
+ const balance = await client.wallet.getBalance();
43
+ console.log('Balance:', formatUSDC(balance), 'USDC');
44
+ ```
45
+
46
+ ## Complete Documentation
47
+
48
+ See [examples/](./examples/) directory for comprehensive usage examples:
49
+
50
+ - `basic-usage.ts` - Basic client operations
51
+ - `contract-interaction.ts` - Smart contract interactions
52
+ - `wallet-connection.ts` - Wallet connection methods
53
+ - `siwe-auth.ts` - SIWE authentication flow
54
+ - `storage-ipfs.ts` - IPFS storage operations
55
+ - `react-app.tsx` - React application with hooks
56
+
57
+ ## Chain Configuration
58
+
59
+ ### Varity L3
60
+
61
+ ```
62
+ Chain ID: 33529
63
+ RPC URL: https://rpc-varity-l3-testnet-wkkzw3oqsj.t.conduit.xyz
64
+ Native Currency: USDC (6 decimals)
65
+ Block Explorer: https://explorer-varity-l3-testnet-wkkzw3oqsj.t.conduit.xyz
66
+ ```
67
+
68
+ ## API Reference
69
+
70
+ - **VarityClient** - Main client class
71
+ - **WalletManager** - Wallet operations
72
+ - **ContractManager** - Smart contract interactions
73
+ - **SIWEAuth** - Authentication
74
+ - **StorageManager** - IPFS storage
75
+
76
+ ## License
77
+
78
+ MIT License - see [LICENSE](./LICENSE) file for details.
79
+
80
+ ---
81
+
82
+ **Made with ❤️ by Varity**
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Varity Client - Main entry point for Varity L3 blockchain interactions
3
+ *
4
+ * This client provides a comprehensive SDK for interacting with Varity L3,
5
+ * including wallet management, contract interactions, authentication, and storage.
6
+ */
7
+ import { type ThirdwebClient, type Chain } from 'thirdweb';
8
+ import { ContractManager } from './contracts/ContractManager';
9
+ import { WalletManager } from './wallet/WalletManager';
10
+ import { SIWEAuth } from './auth/SIWEAuth';
11
+ import { StorageManager } from './storage/StorageManager';
12
+ import type { VarityClientConfig, ChainConfig } from './types';
13
+ export declare const VARITY_L3_CHAIN: ChainConfig;
14
+ export declare const ARBITRUM_SEPOLIA_CHAIN: ChainConfig;
15
+ export declare const ARBITRUM_ONE_CHAIN: ChainConfig;
16
+ /**
17
+ * Main Varity Client Class
18
+ *
19
+ * Provides comprehensive SDK for Varity L3 blockchain interactions.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Initialize client
24
+ * const client = new VarityClient({
25
+ * clientId: 'your-thirdweb-client-id',
26
+ * chain: 'varity-l3'
27
+ * });
28
+ *
29
+ * // Connect wallet
30
+ * await client.wallet.connect({ walletType: 'metamask' });
31
+ *
32
+ * // Read from contract
33
+ * const balance = await client.contracts.read({
34
+ * address: '0x...',
35
+ * abi: [...],
36
+ * functionName: 'balanceOf',
37
+ * args: ['0x...']
38
+ * });
39
+ * ```
40
+ */
41
+ export declare class VarityClient {
42
+ private readonly thirdwebClient;
43
+ private readonly activeChain;
44
+ readonly contracts: ContractManager;
45
+ readonly wallet: WalletManager;
46
+ readonly auth: SIWEAuth;
47
+ readonly storage: StorageManager;
48
+ constructor(config?: VarityClientConfig);
49
+ /**
50
+ * Get chain configuration from config
51
+ */
52
+ private getChainFromConfig;
53
+ /**
54
+ * Get the Thirdweb client instance
55
+ */
56
+ getThirdwebClient(): ThirdwebClient;
57
+ /**
58
+ * Get the active chain
59
+ */
60
+ getChain(): Chain;
61
+ /**
62
+ * Get chain ID
63
+ */
64
+ getChainId(): number;
65
+ /**
66
+ * Get chain name
67
+ */
68
+ getChainName(): string;
69
+ /**
70
+ * Get RPC URL
71
+ */
72
+ getRpcUrl(): string;
73
+ /**
74
+ * Check if connected to Varity L3
75
+ */
76
+ isVarityL3(): boolean;
77
+ /**
78
+ * Get native currency info
79
+ */
80
+ getNativeCurrency(): {
81
+ name?: string;
82
+ symbol?: string;
83
+ decimals?: number;
84
+ };
85
+ /**
86
+ * Get client configuration
87
+ */
88
+ getConfig(): {
89
+ chainId: number;
90
+ chainName: string;
91
+ rpcUrl: string;
92
+ nativeCurrency: {
93
+ name?: string;
94
+ symbol?: string;
95
+ decimals?: number;
96
+ };
97
+ isVarityL3: boolean;
98
+ };
99
+ /**
100
+ * Dispose and cleanup resources
101
+ */
102
+ dispose(): void;
103
+ }
104
+ export default VarityClient;
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ /**
3
+ * Varity Client - Main entry point for Varity L3 blockchain interactions
4
+ *
5
+ * This client provides a comprehensive SDK for interacting with Varity L3,
6
+ * including wallet management, contract interactions, authentication, and storage.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.VarityClient = exports.ARBITRUM_ONE_CHAIN = exports.ARBITRUM_SEPOLIA_CHAIN = exports.VARITY_L3_CHAIN = void 0;
10
+ const thirdweb_1 = require("thirdweb");
11
+ const ContractManager_1 = require("./contracts/ContractManager");
12
+ const WalletManager_1 = require("./wallet/WalletManager");
13
+ const SIWEAuth_1 = require("./auth/SIWEAuth");
14
+ const StorageManager_1 = require("./storage/StorageManager");
15
+ // Thirdweb Client ID loaded from environment
16
+ const DEFAULT_CLIENT_ID = process.env.VARITY_THIRDWEB_CLIENT_ID || process.env.THIRDWEB_CLIENT_ID || '';
17
+ // Varity L3 Chain Configuration
18
+ exports.VARITY_L3_CHAIN = {
19
+ chainId: 33529,
20
+ name: 'Varity L3',
21
+ rpcUrl: 'https://rpc-varity-l3-testnet-wkkzw3oqsj.t.conduit.xyz',
22
+ nativeCurrency: {
23
+ name: 'USDC',
24
+ symbol: 'USDC',
25
+ decimals: 6,
26
+ },
27
+ blockExplorer: 'https://explorer-varity-l3-testnet-wkkzw3oqsj.t.conduit.xyz',
28
+ };
29
+ // Arbitrum Sepolia Configuration
30
+ exports.ARBITRUM_SEPOLIA_CHAIN = {
31
+ chainId: 421614,
32
+ name: 'Arbitrum Sepolia',
33
+ rpcUrl: 'https://sepolia-rollup.arbitrum.io/rpc',
34
+ nativeCurrency: {
35
+ name: 'Ethereum',
36
+ symbol: 'ETH',
37
+ decimals: 18,
38
+ },
39
+ blockExplorer: 'https://sepolia.arbiscan.io',
40
+ };
41
+ // Arbitrum One Configuration
42
+ exports.ARBITRUM_ONE_CHAIN = {
43
+ chainId: 42161,
44
+ name: 'Arbitrum One',
45
+ rpcUrl: 'https://arb1.arbitrum.io/rpc',
46
+ nativeCurrency: {
47
+ name: 'Ethereum',
48
+ symbol: 'ETH',
49
+ decimals: 18,
50
+ },
51
+ blockExplorer: 'https://arbiscan.io',
52
+ };
53
+ /**
54
+ * Main Varity Client Class
55
+ *
56
+ * Provides comprehensive SDK for Varity L3 blockchain interactions.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // Initialize client
61
+ * const client = new VarityClient({
62
+ * clientId: 'your-thirdweb-client-id',
63
+ * chain: 'varity-l3'
64
+ * });
65
+ *
66
+ * // Connect wallet
67
+ * await client.wallet.connect({ walletType: 'metamask' });
68
+ *
69
+ * // Read from contract
70
+ * const balance = await client.contracts.read({
71
+ * address: '0x...',
72
+ * abi: [...],
73
+ * functionName: 'balanceOf',
74
+ * args: ['0x...']
75
+ * });
76
+ * ```
77
+ */
78
+ class VarityClient {
79
+ constructor(config = {}) {
80
+ // Create Thirdweb client
81
+ const clientId = config.clientId || DEFAULT_CLIENT_ID;
82
+ this.thirdwebClient = (0, thirdweb_1.createThirdwebClient)({
83
+ clientId,
84
+ secretKey: config.secretKey,
85
+ });
86
+ // Setup chain
87
+ this.activeChain = this.getChainFromConfig(config);
88
+ // Initialize managers
89
+ this.contracts = new ContractManager_1.ContractManager(this.thirdwebClient, this.activeChain);
90
+ this.wallet = new WalletManager_1.WalletManager(this.thirdwebClient, this.activeChain);
91
+ this.auth = new SIWEAuth_1.SIWEAuth(this.thirdwebClient, this.activeChain);
92
+ this.storage = new StorageManager_1.StorageManager(this.thirdwebClient);
93
+ }
94
+ /**
95
+ * Get chain configuration from config
96
+ */
97
+ getChainFromConfig(config) {
98
+ // If custom chain provided
99
+ if (config.customChain) {
100
+ return (0, thirdweb_1.defineChain)({
101
+ id: config.customChain.chainId,
102
+ name: config.customChain.name,
103
+ rpc: config.customChain.rpcUrl,
104
+ nativeCurrency: config.customChain.nativeCurrency,
105
+ });
106
+ }
107
+ // If Chain object provided directly
108
+ if (typeof config.chain === 'object') {
109
+ return config.chain;
110
+ }
111
+ // Use predefined chains
112
+ const chainName = config.chain || 'varity-l3';
113
+ switch (chainName) {
114
+ case 'varity-l3':
115
+ return (0, thirdweb_1.defineChain)({
116
+ id: exports.VARITY_L3_CHAIN.chainId,
117
+ name: exports.VARITY_L3_CHAIN.name,
118
+ rpc: exports.VARITY_L3_CHAIN.rpcUrl,
119
+ nativeCurrency: exports.VARITY_L3_CHAIN.nativeCurrency,
120
+ });
121
+ case 'arbitrum-sepolia':
122
+ return (0, thirdweb_1.defineChain)({
123
+ id: exports.ARBITRUM_SEPOLIA_CHAIN.chainId,
124
+ name: exports.ARBITRUM_SEPOLIA_CHAIN.name,
125
+ rpc: exports.ARBITRUM_SEPOLIA_CHAIN.rpcUrl,
126
+ nativeCurrency: exports.ARBITRUM_SEPOLIA_CHAIN.nativeCurrency,
127
+ });
128
+ case 'arbitrum-one':
129
+ return (0, thirdweb_1.defineChain)({
130
+ id: exports.ARBITRUM_ONE_CHAIN.chainId,
131
+ name: exports.ARBITRUM_ONE_CHAIN.name,
132
+ rpc: exports.ARBITRUM_ONE_CHAIN.rpcUrl,
133
+ nativeCurrency: exports.ARBITRUM_ONE_CHAIN.nativeCurrency,
134
+ });
135
+ default:
136
+ // Default to Varity L3
137
+ return (0, thirdweb_1.defineChain)({
138
+ id: exports.VARITY_L3_CHAIN.chainId,
139
+ name: exports.VARITY_L3_CHAIN.name,
140
+ rpc: exports.VARITY_L3_CHAIN.rpcUrl,
141
+ nativeCurrency: exports.VARITY_L3_CHAIN.nativeCurrency,
142
+ });
143
+ }
144
+ }
145
+ /**
146
+ * Get the Thirdweb client instance
147
+ */
148
+ getThirdwebClient() {
149
+ return this.thirdwebClient;
150
+ }
151
+ /**
152
+ * Get the active chain
153
+ */
154
+ getChain() {
155
+ return this.activeChain;
156
+ }
157
+ /**
158
+ * Get chain ID
159
+ */
160
+ getChainId() {
161
+ return this.activeChain.id;
162
+ }
163
+ /**
164
+ * Get chain name
165
+ */
166
+ getChainName() {
167
+ return this.activeChain.name || `Chain ${this.activeChain.id}`;
168
+ }
169
+ /**
170
+ * Get RPC URL
171
+ */
172
+ getRpcUrl() {
173
+ return this.activeChain.rpc || '';
174
+ }
175
+ /**
176
+ * Check if connected to Varity L3
177
+ */
178
+ isVarityL3() {
179
+ return this.activeChain.id === exports.VARITY_L3_CHAIN.chainId;
180
+ }
181
+ /**
182
+ * Get native currency info
183
+ */
184
+ getNativeCurrency() {
185
+ return this.activeChain.nativeCurrency || {
186
+ name: 'USDC',
187
+ symbol: 'USDC',
188
+ decimals: 6,
189
+ };
190
+ }
191
+ /**
192
+ * Get client configuration
193
+ */
194
+ getConfig() {
195
+ return {
196
+ chainId: this.getChainId(),
197
+ chainName: this.getChainName(),
198
+ rpcUrl: this.getRpcUrl(),
199
+ nativeCurrency: this.getNativeCurrency(),
200
+ isVarityL3: this.isVarityL3(),
201
+ };
202
+ }
203
+ /**
204
+ * Dispose and cleanup resources
205
+ */
206
+ dispose() {
207
+ // Cleanup any active connections or subscriptions
208
+ this.wallet.disconnect();
209
+ }
210
+ }
211
+ exports.VarityClient = VarityClient;
212
+ exports.default = VarityClient;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Comprehensive Test Suite for Varity Client
3
+ */
4
+ export {};
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ /**
3
+ * Comprehensive Test Suite for Varity Client
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const VarityClient_1 = require("../VarityClient");
7
+ const formatting_1 = require("../utils/formatting");
8
+ // Mock Thirdweb SDK
9
+ jest.mock('thirdweb', () => ({
10
+ createThirdwebClient: jest.fn(() => ({ clientId: 'test' })),
11
+ defineChain: jest.fn((config) => ({
12
+ id: config.id,
13
+ name: config.name,
14
+ rpc: config.rpc,
15
+ nativeCurrency: config.nativeCurrency,
16
+ })),
17
+ getContract: jest.fn(),
18
+ readContract: jest.fn(),
19
+ sendTransaction: jest.fn(),
20
+ upload: jest.fn(),
21
+ download: jest.fn(),
22
+ getWalletBalance: jest.fn(),
23
+ }));
24
+ jest.mock('thirdweb/wallets', () => ({
25
+ createWallet: jest.fn(() => ({
26
+ connect: jest.fn(),
27
+ disconnect: jest.fn(),
28
+ })),
29
+ }));
30
+ describe('VarityClient', () => {
31
+ describe('Client Initialization', () => {
32
+ test('should create client with default configuration', () => {
33
+ const client = new VarityClient_1.VarityClient();
34
+ expect(client).toBeDefined();
35
+ expect(client.getChainId()).toBe(33529); // Varity L3
36
+ });
37
+ test('should create client with custom chain', () => {
38
+ const client = new VarityClient_1.VarityClient({
39
+ chain: 'arbitrum-sepolia',
40
+ });
41
+ expect(client.getChainId()).toBe(421614); // Arbitrum Sepolia
42
+ });
43
+ test('should create client with custom client ID', () => {
44
+ const client = new VarityClient_1.VarityClient({
45
+ clientId: 'custom-client-id',
46
+ });
47
+ expect(client).toBeDefined();
48
+ });
49
+ test('should identify Varity L3 correctly', () => {
50
+ const clientL3 = new VarityClient_1.VarityClient({ chain: 'varity-l3' });
51
+ const clientSepolia = new VarityClient_1.VarityClient({ chain: 'arbitrum-sepolia' });
52
+ expect(clientL3.isVarityL3()).toBe(true);
53
+ expect(clientSepolia.isVarityL3()).toBe(false);
54
+ });
55
+ test('should get correct chain configuration', () => {
56
+ const client = new VarityClient_1.VarityClient({ chain: 'varity-l3' });
57
+ const config = client.getConfig();
58
+ expect(config.chainId).toBe(33529);
59
+ expect(config.chainName).toBe('Varity L3');
60
+ expect(config.isVarityL3).toBe(true);
61
+ expect(config.nativeCurrency.symbol).toBe('USDC');
62
+ expect(config.nativeCurrency.decimals).toBe(6);
63
+ });
64
+ });
65
+ describe('USDC Formatting', () => {
66
+ test('should format USDC correctly', () => {
67
+ expect((0, formatting_1.formatUSDC)(BigInt(1000000))).toBe('1.000000');
68
+ expect((0, formatting_1.formatUSDC)(BigInt(1500000))).toBe('1.500000');
69
+ expect((0, formatting_1.formatUSDC)(BigInt(100))).toBe('0.000100');
70
+ expect((0, formatting_1.formatUSDC)(BigInt(0))).toBe('0.000000');
71
+ });
72
+ test('should parse USDC correctly', () => {
73
+ expect((0, formatting_1.parseUSDC)('1')).toBe(BigInt(1000000));
74
+ expect((0, formatting_1.parseUSDC)('1.5')).toBe(BigInt(1500000));
75
+ expect((0, formatting_1.parseUSDC)('0.000001')).toBe(BigInt(1));
76
+ expect((0, formatting_1.parseUSDC)('10.5')).toBe(BigInt(10500000));
77
+ });
78
+ test('should handle USDC edge cases', () => {
79
+ expect((0, formatting_1.formatUSDC)(BigInt(0))).toBe('0.000000');
80
+ expect((0, formatting_1.parseUSDC)('0')).toBe(BigInt(0));
81
+ expect((0, formatting_1.parseUSDC)('0.000001')).toBe(BigInt(1));
82
+ });
83
+ test('should get USDC amount object', () => {
84
+ const amount = (0, formatting_1.getUSDCAmount)(BigInt(1500000));
85
+ expect(amount.raw).toBe(BigInt(1500000));
86
+ expect(amount.formatted).toBe('1.500000');
87
+ expect(amount.decimals).toBe(6);
88
+ });
89
+ test('should parse and format USDC round-trip', () => {
90
+ const original = '2.5';
91
+ const parsed = (0, formatting_1.parseUSDC)(original);
92
+ const formatted = (0, formatting_1.formatUSDC)(parsed);
93
+ expect(formatted).toBe('2.500000');
94
+ });
95
+ });
96
+ describe('Address Utilities', () => {
97
+ test('should validate addresses correctly', () => {
98
+ expect((0, formatting_1.isValidAddress)('0x1234567890123456789012345678901234567890')).toBe(true);
99
+ expect((0, formatting_1.isValidAddress)('0xABCDEF1234567890ABCDEF1234567890ABCDEF12')).toBe(true);
100
+ expect((0, formatting_1.isValidAddress)('invalid')).toBe(false);
101
+ expect((0, formatting_1.isValidAddress)('0x123')).toBe(false);
102
+ expect((0, formatting_1.isValidAddress)('')).toBe(false);
103
+ });
104
+ test('should shorten addresses correctly', () => {
105
+ const address = '0x1234567890123456789012345678901234567890';
106
+ expect((0, formatting_1.shortenAddress)(address)).toBe('0x1234...7890');
107
+ expect((0, formatting_1.shortenAddress)(address, 6)).toBe('0x123456...567890');
108
+ });
109
+ test('should handle invalid addresses in shortening', () => {
110
+ expect((0, formatting_1.shortenAddress)('invalid')).toBe('invalid');
111
+ });
112
+ });
113
+ describe('Chain Utilities', () => {
114
+ test('should get correct chain names', () => {
115
+ expect((0, formatting_1.getChainName)(33529)).toBe('Varity L3');
116
+ expect((0, formatting_1.getChainName)(421614)).toBe('Arbitrum Sepolia');
117
+ expect((0, formatting_1.getChainName)(42161)).toBe('Arbitrum One');
118
+ expect((0, formatting_1.getChainName)(999999)).toContain('Chain 999999');
119
+ });
120
+ });
121
+ describe('Client Managers', () => {
122
+ test('should have contract manager', () => {
123
+ const client = new VarityClient_1.VarityClient();
124
+ expect(client.contracts).toBeDefined();
125
+ });
126
+ test('should have wallet manager', () => {
127
+ const client = new VarityClient_1.VarityClient();
128
+ expect(client.wallet).toBeDefined();
129
+ });
130
+ test('should have auth manager', () => {
131
+ const client = new VarityClient_1.VarityClient();
132
+ expect(client.auth).toBeDefined();
133
+ });
134
+ test('should have storage manager', () => {
135
+ const client = new VarityClient_1.VarityClient();
136
+ expect(client.storage).toBeDefined();
137
+ });
138
+ });
139
+ });
140
+ describe('WalletManager', () => {
141
+ let client;
142
+ beforeEach(() => {
143
+ client = new VarityClient_1.VarityClient();
144
+ });
145
+ test('should check connection status', () => {
146
+ expect(client.wallet.isConnected()).toBe(false);
147
+ });
148
+ test('should get null address when not connected', () => {
149
+ expect(client.wallet.getAddress()).toBeNull();
150
+ });
151
+ test('should get null account when not connected', () => {
152
+ expect(client.wallet.getAccount()).toBeNull();
153
+ });
154
+ });
155
+ describe('SIWEAuth', () => {
156
+ let client;
157
+ beforeEach(() => {
158
+ client = new VarityClient_1.VarityClient();
159
+ });
160
+ test('should generate SIWE message', async () => {
161
+ const message = await client.auth.generateMessage({
162
+ domain: 'example.com',
163
+ address: '0x1234567890123456789012345678901234567890',
164
+ statement: 'Sign in to example',
165
+ uri: 'https://example.com',
166
+ });
167
+ expect(message).toContain('example.com');
168
+ expect(message).toContain('0x1234567890123456789012345678901234567890');
169
+ expect(message).toContain('Sign in to example');
170
+ });
171
+ test('should format SIWE message correctly', async () => {
172
+ const message = await client.auth.generateMessage({
173
+ domain: 'test.com',
174
+ address: '0x0000000000000000000000000000000000000000',
175
+ statement: 'Test statement',
176
+ });
177
+ expect(message).toContain('URI:');
178
+ expect(message).toContain('Version:');
179
+ expect(message).toContain('Chain ID:');
180
+ expect(message).toContain('Nonce:');
181
+ expect(message).toContain('Issued At:');
182
+ });
183
+ });
184
+ describe('StorageManager', () => {
185
+ let client;
186
+ beforeEach(() => {
187
+ client = new VarityClient_1.VarityClient();
188
+ });
189
+ test('should validate CIDs correctly', () => {
190
+ const validCIDv0 = 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG';
191
+ const invalidCID = 'invalid-cid';
192
+ expect(client.storage.isValidCID(validCIDv0)).toBe(true);
193
+ expect(client.storage.isValidCID(invalidCID)).toBe(false);
194
+ });
195
+ test('should get gateway URL', () => {
196
+ const cid = 'QmTest123';
197
+ const url = client.storage.getGatewayUrl(cid);
198
+ expect(url).toContain(cid);
199
+ expect(url).toContain('ipfs');
200
+ });
201
+ test('should get IPFS URI', () => {
202
+ const cid = 'QmTest123';
203
+ const uri = client.storage.getIPFSUri(cid);
204
+ expect(uri).toBe(`ipfs://${cid}`);
205
+ });
206
+ test('should handle CID with ipfs:// prefix', () => {
207
+ const cid = 'ipfs://QmTest123';
208
+ const uri = client.storage.getIPFSUri(cid);
209
+ expect(uri).toBe('ipfs://QmTest123');
210
+ });
211
+ });
212
+ describe('Error Handling', () => {
213
+ test('should create custom errors', () => {
214
+ const { VarityError, WalletError, ContractError } = require('../types');
215
+ const varietyError = new VarityError('Test error', 'TEST_CODE');
216
+ expect(varietyError.message).toBe('Test error');
217
+ expect(varietyError.code).toBe('TEST_CODE');
218
+ const walletError = new WalletError('Wallet error');
219
+ expect(walletError.name).toBe('WalletError');
220
+ const contractError = new ContractError('Contract error');
221
+ expect(contractError.name).toBe('ContractError');
222
+ });
223
+ });
224
+ describe('Integration Tests', () => {
225
+ test('should create full workflow', () => {
226
+ // Create client
227
+ const client = new VarityClient_1.VarityClient({ chain: 'varity-l3' });
228
+ // Verify client is created
229
+ expect(client).toBeDefined();
230
+ expect(client.isVarityL3()).toBe(true);
231
+ // Verify all managers are available
232
+ expect(client.contracts).toBeDefined();
233
+ expect(client.wallet).toBeDefined();
234
+ expect(client.auth).toBeDefined();
235
+ expect(client.storage).toBeDefined();
236
+ // Test USDC operations
237
+ const amount = (0, formatting_1.parseUSDC)('10.5');
238
+ const formatted = (0, formatting_1.formatUSDC)(amount);
239
+ expect(formatted).toBe('10.500000');
240
+ // Cleanup
241
+ client.dispose();
242
+ });
243
+ test('should handle multiple clients', () => {
244
+ const client1 = new VarityClient_1.VarityClient({ chain: 'varity-l3' });
245
+ const client2 = new VarityClient_1.VarityClient({ chain: 'arbitrum-sepolia' });
246
+ expect(client1.getChainId()).toBe(33529);
247
+ expect(client2.getChainId()).toBe(421614);
248
+ client1.dispose();
249
+ client2.dispose();
250
+ });
251
+ });