@cookill/wallet-adapter 0.1.0 → 2.4.0
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/README.md +93 -69
- package/dist/index.cjs +65 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -48
- package/dist/index.d.ts +51 -48
- package/dist/index.js +64 -16
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +302 -120
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +32 -56
- package/dist/react.d.ts +32 -56
- package/dist/react.js +299 -122
- package/dist/react.js.map +1 -1
- package/dist/standard.cjs +80 -14
- package/dist/standard.cjs.map +1 -1
- package/dist/standard.d.cts +12 -4
- package/dist/standard.d.ts +12 -4
- package/dist/standard.js +80 -15
- package/dist/standard.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @cookill/wallet-adapter
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
> This is a **community-maintained** wallet adapter, NOT an official Rialo package.
|
|
5
|
-
> For official Rialo packages, see: [@rialo/frost](https://www.npmjs.com/package/@rialo/frost)
|
|
3
|
+
Official wallet adapter for **Sheep Wallet** on Rialo blockchain. Provides React hooks, components, and utilities for seamless dApp integration.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## Version 2.3.0
|
|
6
|
+
|
|
7
|
+
- Full TypeScript support
|
|
8
|
+
- React hooks and components
|
|
9
|
+
- Wallet Standard support
|
|
10
|
+
- EIP-6963 compatibility
|
|
11
|
+
- Auto-connect support
|
|
12
|
+
- Multi-network support (Mainnet, Testnet, Devnet, Localnet)
|
|
8
13
|
|
|
9
14
|
## Installation
|
|
10
15
|
|
|
11
16
|
```bash
|
|
12
|
-
npm install @
|
|
17
|
+
npm install @cookill/wallet-adapter
|
|
13
18
|
# or
|
|
14
|
-
yarn add @
|
|
19
|
+
yarn add @cookill/wallet-adapter
|
|
15
20
|
# or
|
|
16
|
-
bun add @
|
|
21
|
+
bun add @cookill/wallet-adapter
|
|
17
22
|
```
|
|
18
23
|
|
|
19
24
|
## Quick Start
|
|
@@ -21,7 +26,7 @@ bun add @cookillabs/wallet-adapter
|
|
|
21
26
|
### React (Recommended)
|
|
22
27
|
|
|
23
28
|
```tsx
|
|
24
|
-
import { WalletProvider, ConnectButton, WalletModal, useWallet } from '@
|
|
29
|
+
import { WalletProvider, ConnectButton, WalletModal, useWallet } from '@cookill/wallet-adapter/react';
|
|
25
30
|
|
|
26
31
|
function App() {
|
|
27
32
|
return (
|
|
@@ -44,7 +49,7 @@ function YourDApp() {
|
|
|
44
49
|
const handleSend = async () => {
|
|
45
50
|
const result = await sendTransaction({
|
|
46
51
|
to: 'RecipientBase58Address...', // Base58 address
|
|
47
|
-
value: '1000000000', // 1
|
|
52
|
+
value: '1000000000', // 1 dRLO in kelvins
|
|
48
53
|
});
|
|
49
54
|
console.log('TX Hash:', result.hash);
|
|
50
55
|
};
|
|
@@ -64,13 +69,13 @@ function YourDApp() {
|
|
|
64
69
|
### Vanilla JavaScript
|
|
65
70
|
|
|
66
71
|
```typescript
|
|
67
|
-
import { RialoWallet, isRialoInstalled, formatBalance } from '@
|
|
72
|
+
import { RialoWallet, isRialoInstalled, formatBalance } from '@cookill/wallet-adapter';
|
|
68
73
|
|
|
69
74
|
const wallet = new RialoWallet();
|
|
70
75
|
|
|
71
76
|
// Check if installed
|
|
72
77
|
if (!isRialoInstalled()) {
|
|
73
|
-
console.log('Please install
|
|
78
|
+
console.log('Please install Sheep Wallet from https://rialo.io/wallet');
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
// Connect
|
|
@@ -122,12 +127,15 @@ const {
|
|
|
122
127
|
accounts, // WalletAccount[] - all accounts
|
|
123
128
|
activeAccount, // WalletAccount | null - current account
|
|
124
129
|
network, // 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
130
|
+
chainId, // 'rialo:devnet' etc
|
|
125
131
|
balance, // string | null - balance in kelvins
|
|
132
|
+
error, // Error | null - last error
|
|
126
133
|
|
|
127
134
|
// Actions
|
|
128
135
|
connect, // () => Promise<WalletAccount[]>
|
|
129
136
|
disconnect, // () => Promise<void>
|
|
130
137
|
switchNetwork, // (network) => Promise<void>
|
|
138
|
+
refreshBalance, // () => Promise<void>
|
|
131
139
|
|
|
132
140
|
// Transactions
|
|
133
141
|
signMessage, // (message: string) => Promise<SignedMessage>
|
|
@@ -154,20 +162,32 @@ const account = useActiveAccount();
|
|
|
154
162
|
// All accounts
|
|
155
163
|
const accounts = useAccounts();
|
|
156
164
|
|
|
157
|
-
// Balance
|
|
158
|
-
const { balance, formatted } = useBalance();
|
|
165
|
+
// Balance with auto-refresh
|
|
166
|
+
const { balance, formatted, refresh } = useBalance();
|
|
167
|
+
|
|
168
|
+
// Network info
|
|
169
|
+
const { network, chainId, config } = useNetwork();
|
|
170
|
+
|
|
171
|
+
// Chain ID only
|
|
172
|
+
const chainId = useChainId();
|
|
159
173
|
|
|
160
|
-
//
|
|
161
|
-
const {
|
|
174
|
+
// Switch network with loading state
|
|
175
|
+
const { switchNetwork, switching, error, currentNetwork } = useSwitchNetwork();
|
|
162
176
|
|
|
163
177
|
// Connect with loading state
|
|
164
|
-
const { connect, connecting, isInstalled } = useConnectWallet();
|
|
178
|
+
const { connect, connecting, isInstalled, error } = useConnectWallet();
|
|
179
|
+
|
|
180
|
+
// Disconnect
|
|
181
|
+
const { disconnect, connected } = useDisconnectWallet();
|
|
165
182
|
|
|
166
183
|
// Sign message with state
|
|
167
|
-
const { sign, signing, signature, error } = useSignMessage();
|
|
184
|
+
const { sign, signing, signature, error, address } = useSignMessage();
|
|
185
|
+
|
|
186
|
+
// Sign transaction with state
|
|
187
|
+
const { sign, signing, signature, error } = useSignTransaction();
|
|
168
188
|
|
|
169
189
|
// Send transaction with state
|
|
170
|
-
const { send, sending, txHash, error } = useSendTransaction();
|
|
190
|
+
const { send, sending, txHash, error, reset } = useSendTransaction();
|
|
171
191
|
```
|
|
172
192
|
|
|
173
193
|
## Components
|
|
@@ -176,10 +196,12 @@ const { send, sending, txHash, error } = useSendTransaction();
|
|
|
176
196
|
|
|
177
197
|
```tsx
|
|
178
198
|
<ConnectButton
|
|
179
|
-
connectLabel="Connect Wallet"
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
199
|
+
connectLabel="Connect Wallet" // Button text when disconnected
|
|
200
|
+
disconnectLabel="Disconnect" // Hover text when connected
|
|
201
|
+
showAddress={true} // Show address when connected
|
|
202
|
+
showBalance={false} // Show balance when connected
|
|
203
|
+
className="my-button" // Custom class
|
|
204
|
+
style={{ ... }} // Custom styles
|
|
183
205
|
/>
|
|
184
206
|
```
|
|
185
207
|
|
|
@@ -201,36 +223,13 @@ const { send, sending, txHash, error } = useSendTransaction();
|
|
|
201
223
|
wallets={[customWallet]} // Additional wallets
|
|
202
224
|
onConnect={(accounts) => console.log('Connected', accounts)}
|
|
203
225
|
onDisconnect={() => console.log('Disconnected')}
|
|
226
|
+
onNetworkChange={(network) => console.log('Network changed', network)}
|
|
204
227
|
onError={(error) => console.error(error)}
|
|
205
228
|
>
|
|
206
229
|
{children}
|
|
207
230
|
</WalletProvider>
|
|
208
231
|
```
|
|
209
232
|
|
|
210
|
-
## Adding Custom Wallets
|
|
211
|
-
|
|
212
|
-
```tsx
|
|
213
|
-
import { WalletProvider, WalletInfo } from '@cookillabs/wallet-adapter/react';
|
|
214
|
-
|
|
215
|
-
const customWallets: WalletInfo[] = [
|
|
216
|
-
{
|
|
217
|
-
id: 'phantom-rialo',
|
|
218
|
-
name: 'Phantom (Rialo)',
|
|
219
|
-
icon: 'https://phantom.app/icon.png',
|
|
220
|
-
installed: !!window.phantom?.rialo,
|
|
221
|
-
downloadUrl: 'https://phantom.app',
|
|
222
|
-
},
|
|
223
|
-
];
|
|
224
|
-
|
|
225
|
-
function App() {
|
|
226
|
-
return (
|
|
227
|
-
<WalletProvider wallets={customWallets}>
|
|
228
|
-
{children}
|
|
229
|
-
</WalletProvider>
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
233
|
## Wallet Standard
|
|
235
234
|
|
|
236
235
|
For advanced integrations using the Wallet Standard:
|
|
@@ -242,7 +241,8 @@ import {
|
|
|
242
241
|
getRialoWallet,
|
|
243
242
|
RIALO_SIGN_MESSAGE,
|
|
244
243
|
RIALO_SIGN_TRANSACTION,
|
|
245
|
-
|
|
244
|
+
RIALO_SIGN_AND_SEND_TRANSACTION,
|
|
245
|
+
} from '@cookill/wallet-adapter/standard';
|
|
246
246
|
|
|
247
247
|
// Get registered wallet
|
|
248
248
|
const wallet = getRialoWallet();
|
|
@@ -277,12 +277,12 @@ Rialo uses **base58** encoded addresses (32-50 characters). Examples:
|
|
|
277
277
|
|
|
278
278
|
## Networks
|
|
279
279
|
|
|
280
|
-
| Network | Chain ID | RPC URL |
|
|
281
|
-
|
|
282
|
-
| Mainnet | rialo:mainnet | https://mainnet.rialo.io:4101 |
|
|
283
|
-
| Testnet | rialo:testnet | https://testnet.rialo.io:4101 |
|
|
284
|
-
| Devnet | rialo:devnet | https://devnet.rialo.io:4101 |
|
|
285
|
-
| Localnet | rialo:localnet | http://localhost:4101 |
|
|
280
|
+
| Network | Chain ID | RPC URL | Symbol |
|
|
281
|
+
|----------|-----------------|----------------------------------|--------|
|
|
282
|
+
| Mainnet | rialo:mainnet | https://mainnet.rialo.io:4101 | RLO |
|
|
283
|
+
| Testnet | rialo:testnet | https://testnet.rialo.io:4101 | tRLO |
|
|
284
|
+
| Devnet | rialo:devnet | https://devnet.rialo.io:4101 | dRLO |
|
|
285
|
+
| Localnet | rialo:localnet | http://localhost:4101 | lRLO |
|
|
286
286
|
|
|
287
287
|
## Utility Functions
|
|
288
288
|
|
|
@@ -292,10 +292,13 @@ import {
|
|
|
292
292
|
formatBalance, // (kelvins, decimals?) => "1.0000"
|
|
293
293
|
parseBalance, // (rlo) => bigint (kelvins)
|
|
294
294
|
isValidAddress, // (address) => boolean (base58 validation)
|
|
295
|
+
toChainId, // (network) => 'rialo:devnet'
|
|
296
|
+
fromChainId, // (chainId) => 'devnet'
|
|
295
297
|
isRialoInstalled, // () => boolean
|
|
296
298
|
getRialoProvider, // () => RialoProvider | undefined
|
|
299
|
+
waitForRialoProvider, // (timeout?) => Promise<RialoProvider | undefined>
|
|
297
300
|
NETWORKS, // Network configurations
|
|
298
|
-
} from '@
|
|
301
|
+
} from '@cookill/wallet-adapter';
|
|
299
302
|
```
|
|
300
303
|
|
|
301
304
|
## TypeScript
|
|
@@ -308,12 +311,14 @@ import type {
|
|
|
308
311
|
TransactionRequest,
|
|
309
312
|
TransactionResult,
|
|
310
313
|
SignedMessage,
|
|
314
|
+
BalanceResult,
|
|
311
315
|
NetworkConfig,
|
|
312
316
|
WalletInfo,
|
|
313
317
|
RialoProvider,
|
|
314
318
|
RialoNetwork,
|
|
315
319
|
RialoChain,
|
|
316
|
-
|
|
320
|
+
WalletEvent,
|
|
321
|
+
} from '@cookill/wallet-adapter';
|
|
317
322
|
```
|
|
318
323
|
|
|
319
324
|
## Building a Compatible Wallet
|
|
@@ -323,35 +328,54 @@ To make your wallet compatible with this adapter, inject a provider at `window.r
|
|
|
323
328
|
```typescript
|
|
324
329
|
window.rialo = {
|
|
325
330
|
isRialo: true,
|
|
326
|
-
|
|
331
|
+
isSheepWallet: true, // Identify as Sheep Wallet
|
|
332
|
+
name: 'Sheep Wallet',
|
|
333
|
+
walletName: 'Sheep Wallet',
|
|
334
|
+
version: '2.3.0',
|
|
327
335
|
|
|
328
336
|
// Connection
|
|
329
|
-
connect: async () => ['
|
|
337
|
+
connect: async () => [{ address: '5YNmS1R9...', publicKey: '5YNmS1R9...' }],
|
|
330
338
|
disconnect: async () => {},
|
|
331
339
|
isConnected: async () => true,
|
|
332
|
-
getAccounts: async () => ['
|
|
340
|
+
getAccounts: async () => [{ address: '5YNmS1R9...' }],
|
|
333
341
|
|
|
334
|
-
// Transactions
|
|
335
|
-
signTransaction: async (tx) => ({ signature: '...
|
|
336
|
-
sendTransaction: async (tx) => ({ hash: '...
|
|
337
|
-
signAndSendTransaction: async (tx) => ({ hash: '...
|
|
342
|
+
// Transactions
|
|
343
|
+
signTransaction: async (tx) => ({ signature: '...', signedTransaction: '...' }),
|
|
344
|
+
sendTransaction: async (tx) => ({ hash: '...', status: 'pending' }),
|
|
345
|
+
signAndSendTransaction: async (tx) => ({ hash: '...', status: 'pending' }),
|
|
338
346
|
|
|
339
347
|
// Message signing
|
|
340
348
|
signMessage: async (message) => ({
|
|
341
|
-
signature: '...
|
|
349
|
+
signature: '...',
|
|
342
350
|
message,
|
|
343
|
-
address: '
|
|
351
|
+
address: '5YNmS1R9...'
|
|
344
352
|
}),
|
|
345
353
|
|
|
346
354
|
// Network
|
|
347
|
-
getNetwork: async () => '
|
|
348
|
-
switchNetwork: async (network) => {},
|
|
349
|
-
|
|
355
|
+
getNetwork: async () => 'devnet',
|
|
356
|
+
switchNetwork: async (network) => ({ success: true }),
|
|
357
|
+
getChainId: async () => 'rialo:devnet',
|
|
358
|
+
getBalance: async (address) => ({
|
|
359
|
+
balance: '1.0',
|
|
360
|
+
balanceKelvins: '1000000000',
|
|
361
|
+
formatted: '1.0000 RLO'
|
|
362
|
+
}),
|
|
350
363
|
|
|
351
364
|
// Events
|
|
352
365
|
on: (event, callback) => () => {},
|
|
366
|
+
off: (event, callback) => {},
|
|
353
367
|
removeListener: (event, callback) => {},
|
|
354
368
|
removeAllListeners: (event) => {},
|
|
369
|
+
|
|
370
|
+
// Utilities (optional)
|
|
371
|
+
utils: {
|
|
372
|
+
isValidAddress: (address) => /^[1-9A-HJ-NP-Za-km-z]{32,50}$/.test(address),
|
|
373
|
+
formatAddress: (address, chars = 4) => `${address.slice(0, chars)}...${address.slice(-chars)}`,
|
|
374
|
+
},
|
|
375
|
+
|
|
376
|
+
// Wallet Standard features (optional)
|
|
377
|
+
features: ['standard:connect', 'standard:disconnect', 'rialo:signTransaction', ...],
|
|
378
|
+
supportsFeature: (feature) => true,
|
|
355
379
|
};
|
|
356
380
|
```
|
|
357
381
|
|
|
@@ -366,4 +390,4 @@ npm publish --access public
|
|
|
366
390
|
|
|
367
391
|
## License
|
|
368
392
|
|
|
369
|
-
MIT ©
|
|
393
|
+
MIT © CookilLabs
|
package/dist/index.cjs
CHANGED
|
@@ -9,28 +9,36 @@ var NETWORKS = {
|
|
|
9
9
|
name: "Rialo Mainnet",
|
|
10
10
|
rpcUrl: "https://mainnet.rialo.io:4101",
|
|
11
11
|
wsUrl: "wss://mainnet.rialo.io:4102",
|
|
12
|
-
explorerUrl: "https://explorer.rialo.io"
|
|
12
|
+
explorerUrl: "https://explorer.rialo.io",
|
|
13
|
+
symbol: "RLO",
|
|
14
|
+
decimals: 9
|
|
13
15
|
},
|
|
14
16
|
testnet: {
|
|
15
17
|
chainId: "rialo:testnet",
|
|
16
18
|
name: "Rialo Testnet",
|
|
17
19
|
rpcUrl: "https://testnet.rialo.io:4101",
|
|
18
20
|
wsUrl: "wss://testnet.rialo.io:4102",
|
|
19
|
-
explorerUrl: "https://testnet.explorer.rialo.io"
|
|
21
|
+
explorerUrl: "https://testnet.explorer.rialo.io",
|
|
22
|
+
symbol: "tRLO",
|
|
23
|
+
decimals: 9
|
|
20
24
|
},
|
|
21
25
|
devnet: {
|
|
22
26
|
chainId: "rialo:devnet",
|
|
23
27
|
name: "Rialo Devnet",
|
|
24
28
|
rpcUrl: "https://devnet.rialo.io:4101",
|
|
25
29
|
wsUrl: "wss://devnet.rialo.io:4102",
|
|
26
|
-
explorerUrl: "https://devnet.explorer.rialo.io"
|
|
30
|
+
explorerUrl: "https://devnet.explorer.rialo.io",
|
|
31
|
+
symbol: "dRLO",
|
|
32
|
+
decimals: 9
|
|
27
33
|
},
|
|
28
34
|
localnet: {
|
|
29
35
|
chainId: "rialo:localnet",
|
|
30
36
|
name: "Rialo Localnet",
|
|
31
37
|
rpcUrl: "http://localhost:4101",
|
|
32
38
|
wsUrl: "ws://localhost:4102",
|
|
33
|
-
explorerUrl: "http://localhost:3000"
|
|
39
|
+
explorerUrl: "http://localhost:3000",
|
|
40
|
+
symbol: "lRLO",
|
|
41
|
+
decimals: 9
|
|
34
42
|
}
|
|
35
43
|
};
|
|
36
44
|
function isRialoInstalled() {
|
|
@@ -48,16 +56,29 @@ function waitForRialoProvider(timeout = 3e3) {
|
|
|
48
56
|
resolve(getRialoProvider());
|
|
49
57
|
return;
|
|
50
58
|
}
|
|
59
|
+
let resolved = false;
|
|
51
60
|
const checkInterval = setInterval(() => {
|
|
52
|
-
if (isRialoInstalled()) {
|
|
61
|
+
if (isRialoInstalled() && !resolved) {
|
|
62
|
+
resolved = true;
|
|
53
63
|
clearInterval(checkInterval);
|
|
54
64
|
resolve(getRialoProvider());
|
|
55
65
|
}
|
|
56
66
|
}, 100);
|
|
57
67
|
setTimeout(() => {
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
if (!resolved) {
|
|
69
|
+
resolved = true;
|
|
70
|
+
clearInterval(checkInterval);
|
|
71
|
+
resolve(void 0);
|
|
72
|
+
}
|
|
60
73
|
}, timeout);
|
|
74
|
+
const handler = () => {
|
|
75
|
+
if (!resolved) {
|
|
76
|
+
resolved = true;
|
|
77
|
+
clearInterval(checkInterval);
|
|
78
|
+
resolve(getRialoProvider());
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
window.addEventListener("rialo#initialized", handler, { once: true });
|
|
61
82
|
});
|
|
62
83
|
}
|
|
63
84
|
var RialoWallet = class {
|
|
@@ -65,7 +86,24 @@ var RialoWallet = class {
|
|
|
65
86
|
this._connected = false;
|
|
66
87
|
this._accounts = [];
|
|
67
88
|
this._network = "devnet";
|
|
89
|
+
this._listeners = /* @__PURE__ */ new Map();
|
|
68
90
|
this.provider = getRialoProvider();
|
|
91
|
+
this.setupEvents();
|
|
92
|
+
}
|
|
93
|
+
setupEvents() {
|
|
94
|
+
if (!this.provider) return;
|
|
95
|
+
this.provider.on("disconnect", () => {
|
|
96
|
+
this._connected = false;
|
|
97
|
+
this._accounts = [];
|
|
98
|
+
});
|
|
99
|
+
this.provider.on("accountsChanged", (data) => {
|
|
100
|
+
const accounts = data;
|
|
101
|
+
this._accounts = accounts;
|
|
102
|
+
});
|
|
103
|
+
this.provider.on("networkChanged", (data) => {
|
|
104
|
+
const { network } = data;
|
|
105
|
+
this._network = network;
|
|
106
|
+
});
|
|
69
107
|
}
|
|
70
108
|
get isInstalled() {
|
|
71
109
|
return isRialoInstalled();
|
|
@@ -82,16 +120,19 @@ var RialoWallet = class {
|
|
|
82
120
|
get network() {
|
|
83
121
|
return this._network;
|
|
84
122
|
}
|
|
123
|
+
get chainId() {
|
|
124
|
+
return `rialo:${this._network}`;
|
|
125
|
+
}
|
|
85
126
|
async connect() {
|
|
86
127
|
this.provider = getRialoProvider();
|
|
87
128
|
if (!this.provider) {
|
|
88
129
|
throw new Error("Rialo Wallet not installed. Download at https://rialo.io/wallet");
|
|
89
130
|
}
|
|
90
|
-
const
|
|
91
|
-
this._accounts =
|
|
131
|
+
const accounts = await this.provider.connect();
|
|
132
|
+
this._accounts = accounts;
|
|
92
133
|
this._connected = true;
|
|
93
|
-
const
|
|
94
|
-
this._network =
|
|
134
|
+
const network = await this.provider.getNetwork();
|
|
135
|
+
this._network = network;
|
|
95
136
|
return this._accounts;
|
|
96
137
|
}
|
|
97
138
|
async disconnect() {
|
|
@@ -130,7 +171,9 @@ var RialoWallet = class {
|
|
|
130
171
|
if (!this.provider) {
|
|
131
172
|
throw new Error("Wallet not available");
|
|
132
173
|
}
|
|
133
|
-
|
|
174
|
+
const result = await this.provider.getBalance(address);
|
|
175
|
+
if (typeof result === "string") return result;
|
|
176
|
+
return result.balance;
|
|
134
177
|
}
|
|
135
178
|
async switchNetwork(network) {
|
|
136
179
|
if (!this.provider) {
|
|
@@ -153,7 +196,7 @@ function formatAddress(address, chars = 4) {
|
|
|
153
196
|
return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
|
|
154
197
|
}
|
|
155
198
|
function formatBalance(kelvins, decimals = 4) {
|
|
156
|
-
const value = typeof kelvins === "string" ? BigInt(kelvins) : kelvins;
|
|
199
|
+
const value = typeof kelvins === "string" ? BigInt(kelvins || "0") : kelvins;
|
|
157
200
|
const rlo = Number(value) / 1e9;
|
|
158
201
|
return rlo.toFixed(decimals);
|
|
159
202
|
}
|
|
@@ -164,8 +207,13 @@ function parseBalance(rlo) {
|
|
|
164
207
|
function isValidAddress(address) {
|
|
165
208
|
if (!address || typeof address !== "string") return false;
|
|
166
209
|
if (address.length < 32 || address.length > 50) return false;
|
|
167
|
-
|
|
168
|
-
|
|
210
|
+
return /^[1-9A-HJ-NP-Za-km-z]+$/.test(address);
|
|
211
|
+
}
|
|
212
|
+
function toChainId(network) {
|
|
213
|
+
return `rialo:${network}`;
|
|
214
|
+
}
|
|
215
|
+
function fromChainId(chainId) {
|
|
216
|
+
return chainId.replace("rialo:", "");
|
|
169
217
|
}
|
|
170
218
|
var src_default = RialoWallet;
|
|
171
219
|
|
|
@@ -174,10 +222,12 @@ exports.RialoWallet = RialoWallet;
|
|
|
174
222
|
exports.default = src_default;
|
|
175
223
|
exports.formatAddress = formatAddress;
|
|
176
224
|
exports.formatBalance = formatBalance;
|
|
225
|
+
exports.fromChainId = fromChainId;
|
|
177
226
|
exports.getRialoProvider = getRialoProvider;
|
|
178
227
|
exports.isRialoInstalled = isRialoInstalled;
|
|
179
228
|
exports.isValidAddress = isValidAddress;
|
|
180
229
|
exports.parseBalance = parseBalance;
|
|
230
|
+
exports.toChainId = toChainId;
|
|
181
231
|
exports.waitForRialoProvider = waitForRialoProvider;
|
|
182
232
|
//# sourceMappingURL=index.cjs.map
|
|
183
233
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAwEO,IAAM,QAAA,GAAgD;AAAA,EAC3D,OAAA,EAAS;AAAA,IAC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AA,GAAQ,CAAA,GAAI,GAAG,OAAO,OAAA;AAC5C,EAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,KAAA,GAAQ,CAAC,CAAC,CAAA,GAAA,EAAM,OAAA,CAAQ,KAAA,CAAM,CAAC,KAAK,CAAC,CAAA,CAAA;AAClE;AAKO,SAAS,aAAA,CAAc,OAAA,EAA0B,QAAA,GAAW,CAAA,EAAW;AAC5E,EAAA,MAAM,QAAQ,OAAO,OAAA,KAAY,QAAA,GAAW,MAAA,CAAO,OAAO,CAAA,GAAI,OAAA;AAC9D,EAAA,MAAM,GAAA,GAAM,MAAA,CAAO,KAAK,CAAA,GAAI,GAAA;AAC5B,EAAA,OAAO,GAAA,CAAI,QAAQ,QAAQ,CAAA;AAC7B;AAKO,SAAS,aAAa,GAAA,EAA8B;AACzD,EAAA,MAAM,QAAQ,OAAO,GAAA,KAAQ,QAAA,GAAW,UAAA,CAAW,GAAG,CAAA,GAAI,GAAA;AAC1D,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,KAAA,GAAQ,GAAa,CAAC,CAAA;AACjD;AAMO,SAAS,eAAe,OAAA,EAA0B;AACvD,EAAA,IAAI,CAAC,OAAA,IAAW,OAAO,OAAA,KAAY,UAAU,OAAO,KAAA;AACpD,EAAA,IAAI,QAAQ,MAAA,GAAS,EAAA,IAAM,OAAA,CAAQ,MAAA,GAAS,IAAI,OAAO,KAAA;AAGvD,EAAA,MAAM,WAAA,GAAc,yBAAA;AACpB,EAAA,OAAO,WAAA,CAAY,KAAK,OAAO,CAAA;AACjC;AAoBA,IAAO,WAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * @cookillabs/wallet-adapter\n * Community wallet adapter for Rialo blockchain dApps\n * \n * ⚠️ DISCLAIMER: This is a community package, NOT officially maintained by Rialo.\n * For official Rialo packages, see: https://www.npmjs.com/package/@rialo/frost\n */\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Supported Rialo chains */\nexport type RialoChain = 'rialo:mainnet' | 'rialo:testnet' | 'rialo:devnet' | 'rialo:localnet';\n\n/** Network shorthand */\nexport type RialoNetwork = 'mainnet' | 'testnet' | 'devnet' | 'localnet';\n\n/** Wallet account */\nexport interface WalletAccount {\n address: string;\n publicKey?: Uint8Array | string;\n label?: string;\n}\n\n/** Transaction request */\nexport interface TransactionRequest {\n to: string;\n value: string;\n data?: string;\n memo?: string;\n}\n\n/** Transaction result */\nexport interface TransactionResult {\n hash: string;\n status: 'pending' | 'confirmed' | 'failed';\n blockNumber?: number;\n}\n\n/** Signed message */\nexport interface SignedMessage {\n signature: string;\n message: string;\n address: string;\n}\n\n/** Network configuration */\nexport interface NetworkConfig {\n chainId: string;\n name: string;\n rpcUrl: string;\n wsUrl?: string;\n explorerUrl?: string;\n}\n\n/** Wallet info for registry */\nexport interface WalletInfo {\n id: string;\n name: string;\n icon: string;\n installed?: boolean;\n downloadUrl?: string;\n}\n\n/** Wallet adapter events */\nexport type WalletEvent = 'connect' | 'disconnect' | 'accountChange' | 'networkChange' | 'error';\n\n// ============================================================================\n// Network Configurations\n// ============================================================================\n\nexport const NETWORKS: Record<RialoNetwork, NetworkConfig> = {\n mainnet: {\n chainId: 'rialo:mainnet',\n name: 'Rialo Mainnet',\n rpcUrl: 'https://mainnet.rialo.io:4101',\n wsUrl: 'wss://mainnet.rialo.io:4102',\n explorerUrl: 'https://explorer.rialo.io',\n },\n testnet: {\n chainId: 'rialo:testnet',\n name: 'Rialo Testnet',\n rpcUrl: 'https://testnet.rialo.io:4101',\n wsUrl: 'wss://testnet.rialo.io:4102',\n explorerUrl: 'https://testnet.explorer.rialo.io',\n },\n devnet: {\n chainId: 'rialo:devnet',\n name: 'Rialo Devnet',\n rpcUrl: 'https://devnet.rialo.io:4101',\n wsUrl: 'wss://devnet.rialo.io:4102',\n explorerUrl: 'https://devnet.explorer.rialo.io',\n },\n localnet: {\n chainId: 'rialo:localnet',\n name: 'Rialo Localnet',\n rpcUrl: 'http://localhost:4101',\n wsUrl: 'ws://localhost:4102',\n explorerUrl: 'http://localhost:3000',\n },\n};\n\n// ============================================================================\n// Wallet Provider Interface\n// ============================================================================\n\n/**\n * Provider interface injected by Rialo Wallet extension\n * Available at window.rialo when extension is installed\n */\nexport interface RialoProvider {\n isRialo: boolean;\n version: string;\n\n // Connection\n connect(): Promise<string[]>;\n disconnect(): Promise<void>;\n isConnected(): Promise<boolean>;\n getAccounts(): Promise<string[]>;\n\n // Transactions\n signTransaction(tx: TransactionRequest): Promise<{ signature: string; rawTransaction?: string }>;\n sendTransaction(tx: TransactionRequest): Promise<TransactionResult>;\n signAndSendTransaction(tx: TransactionRequest): Promise<TransactionResult>;\n\n // Message signing\n signMessage(message: string): Promise<SignedMessage>;\n\n // Network\n getNetwork(): Promise<string>;\n switchNetwork(network: RialoNetwork): Promise<void>;\n getBalance(address?: string): Promise<string>;\n\n // Events\n on(event: WalletEvent, callback: (data: unknown) => void): () => void;\n removeListener(event: WalletEvent, callback: (data: unknown) => void): void;\n removeAllListeners(event?: WalletEvent): void;\n}\n\n// ============================================================================\n// Detection & Access\n// ============================================================================\n\n/**\n * Check if Rialo Wallet extension is installed\n */\nexport function isRialoInstalled(): boolean {\n if (typeof window === 'undefined') return false;\n return !!(window as RialoWindow).rialo?.isRialo;\n}\n\n/**\n * Get the Rialo provider if available\n */\nexport function getRialoProvider(): RialoProvider | undefined {\n if (typeof window === 'undefined') return undefined;\n const rialo = (window as RialoWindow).rialo;\n return rialo?.isRialo ? rialo : undefined;\n}\n\n/**\n * Wait for Rialo provider to be available (with timeout)\n */\nexport function waitForRialoProvider(timeout = 3000): Promise<RialoProvider | undefined> {\n return new Promise((resolve) => {\n if (isRialoInstalled()) {\n resolve(getRialoProvider());\n return;\n }\n\n const checkInterval = setInterval(() => {\n if (isRialoInstalled()) {\n clearInterval(checkInterval);\n resolve(getRialoProvider());\n }\n }, 100);\n\n setTimeout(() => {\n clearInterval(checkInterval);\n resolve(undefined);\n }, timeout);\n });\n}\n\n// ============================================================================\n// Simple Wallet Class (Non-React)\n// ============================================================================\n\nexport class RialoWallet {\n private provider: RialoProvider | undefined;\n private _connected = false;\n private _accounts: WalletAccount[] = [];\n private _network: RialoNetwork = 'devnet';\n\n constructor() {\n this.provider = getRialoProvider();\n }\n\n get isInstalled(): boolean {\n return isRialoInstalled();\n }\n\n get connected(): boolean {\n return this._connected;\n }\n\n get accounts(): WalletAccount[] {\n return this._accounts;\n }\n\n get activeAccount(): WalletAccount | undefined {\n return this._accounts[0];\n }\n\n get network(): RialoNetwork {\n return this._network;\n }\n\n async connect(): Promise<WalletAccount[]> {\n this.provider = getRialoProvider();\n if (!this.provider) {\n throw new Error('Rialo Wallet not installed. Download at https://rialo.io/wallet');\n }\n\n const addresses = await this.provider.connect();\n this._accounts = addresses.map((address) => ({ address }));\n this._connected = true;\n\n const networkStr = await this.provider.getNetwork();\n this._network = networkStr.replace('rialo:', '') as RialoNetwork;\n\n return this._accounts;\n }\n\n async disconnect(): Promise<void> {\n if (this.provider) {\n await this.provider.disconnect();\n }\n this._connected = false;\n this._accounts = [];\n }\n\n async signMessage(message: string): Promise<SignedMessage> {\n if (!this.provider || !this._connected) {\n throw new Error('Wallet not connected');\n }\n return this.provider.signMessage(message);\n }\n\n async signTransaction(tx: TransactionRequest): Promise<string> {\n if (!this.provider || !this._connected) {\n throw new Error('Wallet not connected');\n }\n const result = await this.provider.signTransaction(tx);\n return result.signature;\n }\n\n async sendTransaction(tx: TransactionRequest): Promise<TransactionResult> {\n if (!this.provider || !this._connected) {\n throw new Error('Wallet not connected');\n }\n return this.provider.sendTransaction(tx);\n }\n\n async signAndSendTransaction(tx: TransactionRequest): Promise<TransactionResult> {\n if (!this.provider || !this._connected) {\n throw new Error('Wallet not connected');\n }\n return this.provider.signAndSendTransaction(tx);\n }\n\n async getBalance(address?: string): Promise<string> {\n if (!this.provider) {\n throw new Error('Wallet not available');\n }\n return this.provider.getBalance(address);\n }\n\n async switchNetwork(network: RialoNetwork): Promise<void> {\n if (!this.provider) {\n throw new Error('Wallet not available');\n }\n await this.provider.switchNetwork(network);\n this._network = network;\n }\n\n on(event: WalletEvent, callback: (data: unknown) => void): () => void {\n if (!this.provider) {\n return () => {};\n }\n return this.provider.on(event, callback);\n }\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\n/**\n * Format address for display (truncated base58)\n */\nexport function formatAddress(address: string, chars = 4): string {\n if (!address) return '';\n if (address.length <= chars * 2 + 3) return address;\n return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;\n}\n\n/**\n * Format balance from kelvins (smallest unit) to RLO\n */\nexport function formatBalance(kelvins: string | bigint, decimals = 4): string {\n const value = typeof kelvins === 'string' ? BigInt(kelvins) : kelvins;\n const rlo = Number(value) / 1_000_000_000;\n return rlo.toFixed(decimals);\n}\n\n/**\n * Parse RLO to kelvins\n */\nexport function parseBalance(rlo: string | number): bigint {\n const value = typeof rlo === 'string' ? parseFloat(rlo) : rlo;\n return BigInt(Math.floor(value * 1_000_000_000));\n}\n\n/**\n * Validate Rialo address format (base58)\n * Real Rialo addresses are base58 encoded public keys (32-50 chars)\n */\nexport function isValidAddress(address: string): boolean {\n if (!address || typeof address !== 'string') return false;\n if (address.length < 32 || address.length > 50) return false;\n \n // Base58 character set (no 0, O, I, l)\n const base58Regex = /^[1-9A-HJ-NP-Za-km-z]+$/;\n return base58Regex.test(address);\n}\n\n// ============================================================================\n// Window Extension\n// ============================================================================\n\ninterface RialoWindow extends Window {\n rialo?: RialoProvider;\n}\n\ndeclare global {\n interface Window {\n rialo?: RialoProvider;\n }\n}\n\n// ============================================================================\n// Default Export\n// ============================================================================\n\nexport default RialoWallet;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AA2EO,IAAM,QAAA,GAAgD;AAAA,EAC3D,OAAA,EAAS;AAAA,IACP,OAAA,EAAS,eAAA;AAAA,IACT,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ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AO,SAAS,OAAO,CAAA,CAAA;AACzB;AAEO,SAAS,YAAY,OAAA,EAAmC;AAC7D,EAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,QAAA,EAAU,EAAE,CAAA;AACrC;AAqBA,IAAO,WAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * @cookill/wallet-adapter v2.3.0\n * Sheep Wallet adapter for Rialo blockchain dApps\n */\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport type RialoChain = 'rialo:mainnet' | 'rialo:testnet' | 'rialo:devnet' | 'rialo:localnet';\nexport type RialoNetwork = 'mainnet' | 'testnet' | 'devnet' | 'localnet';\n\nexport interface WalletAccount {\n address: string;\n publicKey?: Uint8Array | string;\n label?: string;\n}\n\nexport interface TransactionRequest {\n to: string;\n value: string;\n data?: string;\n memo?: string;\n}\n\nexport interface TransactionResult {\n hash: string;\n signature?: string;\n status: 'pending' | 'confirmed' | 'failed';\n blockNumber?: number;\n}\n\nexport interface SignedMessage {\n signature: string;\n message: string;\n address: string;\n publicKey?: string;\n}\n\nexport interface BalanceResult {\n balance: string;\n balanceKelvins: string;\n formatted: string;\n}\n\nexport interface NetworkConfig {\n chainId: string;\n name: string;\n rpcUrl: string;\n wsUrl?: string;\n explorerUrl?: string;\n symbol: string;\n decimals: number;\n}\n\nexport interface WalletInfo {\n id: string;\n name: string;\n icon: string;\n installed?: boolean;\n downloadUrl?: string;\n}\n\nexport type WalletEvent = \n | 'connect' \n | 'disconnect' \n | 'accountsChanged'\n | 'networkChanged' \n | 'chainChanged'\n | 'error';\n\n// ============================================================================\n// Network Configurations\n// ============================================================================\n\nexport const NETWORKS: Record<RialoNetwork, NetworkConfig> = {\n mainnet: {\n chainId: 'rialo:mainnet',\n name: 'Rialo Mainnet',\n rpcUrl: 'https://mainnet.rialo.io:4101',\n wsUrl: 'wss://mainnet.rialo.io:4102',\n explorerUrl: 'https://explorer.rialo.io',\n symbol: 'RLO',\n decimals: 9,\n },\n testnet: {\n chainId: 'rialo:testnet',\n name: 'Rialo Testnet',\n rpcUrl: 'https://testnet.rialo.io:4101',\n wsUrl: 'wss://testnet.rialo.io:4102',\n explorerUrl: 'https://testnet.explorer.rialo.io',\n symbol: 'tRLO',\n decimals: 9,\n },\n devnet: {\n chainId: 'rialo:devnet',\n name: 'Rialo Devnet',\n rpcUrl: 'https://devnet.rialo.io:4101',\n wsUrl: 'wss://devnet.rialo.io:4102',\n explorerUrl: 'https://devnet.explorer.rialo.io',\n symbol: 'dRLO',\n decimals: 9,\n },\n localnet: {\n chainId: 'rialo:localnet',\n name: 'Rialo Localnet',\n rpcUrl: 'http://localhost:4101',\n wsUrl: 'ws://localhost:4102',\n explorerUrl: 'http://localhost:3000',\n symbol: 'lRLO',\n decimals: 9,\n },\n};\n\n// ============================================================================\n// Provider Interface\n// ============================================================================\n\nexport interface RialoProvider {\n // Metadata\n isRialo: boolean;\n isSheepWallet?: boolean;\n name?: string;\n walletName?: string;\n version: string;\n icon?: string;\n\n // Connection\n connect(options?: { silent?: boolean }): Promise<WalletAccount[]>;\n disconnect(): Promise<void>;\n isConnected(): Promise<boolean>;\n getAccounts(): Promise<WalletAccount[]>;\n\n // Transactions\n signTransaction(tx: TransactionRequest): Promise<{ signature: string; signedTransaction?: string; rawTransaction?: string }>;\n sendTransaction(tx: TransactionRequest): Promise<TransactionResult>;\n signAndSendTransaction(tx: TransactionRequest): Promise<TransactionResult>;\n signAllTransactions?(txs: TransactionRequest[]): Promise<{ signedTransactions: string[] }>;\n\n // Message signing\n signMessage(message: string | Uint8Array): Promise<SignedMessage>;\n\n // Network\n getNetwork(): Promise<RialoNetwork>;\n switchNetwork(network: RialoNetwork): Promise<{ success: boolean }>;\n getChainId(): Promise<string>;\n getBalance(address?: string): Promise<BalanceResult | string>;\n\n // Events\n on(event: WalletEvent, callback: (data: unknown) => void): () => void;\n off?(event: WalletEvent, callback: (data: unknown) => void): void;\n removeListener(event: WalletEvent, callback: (data: unknown) => void): void;\n removeAllListeners(event?: WalletEvent): void;\n\n // Utilities\n utils?: {\n isValidAddress(address: string): boolean;\n formatAddress(address: string, chars?: number): string;\n };\n\n // Wallet Standard\n features?: string[];\n supportsFeature?(feature: string): boolean;\n\n // State getters\n readonly connected?: boolean;\n readonly accounts?: WalletAccount[];\n readonly address?: string | null;\n readonly publicKey?: string | null;\n readonly network?: RialoNetwork;\n readonly chainId?: string;\n}\n\n// ============================================================================\n// Detection & Access\n// ============================================================================\n\nexport function isRialoInstalled(): boolean {\n if (typeof window === 'undefined') return false;\n return !!(window as RialoWindow).rialo?.isRialo;\n}\n\nexport function getRialoProvider(): RialoProvider | undefined {\n if (typeof window === 'undefined') return undefined;\n const rialo = (window as RialoWindow).rialo;\n return rialo?.isRialo ? rialo : undefined;\n}\n\nexport function waitForRialoProvider(timeout = 3000): Promise<RialoProvider | undefined> {\n return new Promise((resolve) => {\n if (isRialoInstalled()) {\n resolve(getRialoProvider());\n return;\n }\n\n let resolved = false;\n const checkInterval = setInterval(() => {\n if (isRialoInstalled() && !resolved) {\n resolved = true;\n clearInterval(checkInterval);\n resolve(getRialoProvider());\n }\n }, 100);\n\n setTimeout(() => {\n if (!resolved) {\n resolved = true;\n clearInterval(checkInterval);\n resolve(undefined);\n }\n }, timeout);\n\n // Also listen for initialization event\n const handler = () => {\n if (!resolved) {\n resolved = true;\n clearInterval(checkInterval);\n resolve(getRialoProvider());\n }\n };\n window.addEventListener('rialo#initialized', handler, { once: true });\n });\n}\n\n// ============================================================================\n// Simple Wallet Class (Non-React)\n// ============================================================================\n\nexport class RialoWallet {\n private provider: RialoProvider | undefined;\n private _connected = false;\n private _accounts: WalletAccount[] = [];\n private _network: RialoNetwork = 'devnet';\n private _listeners: Map<string, Set<() => void>> = new Map();\n\n constructor() {\n this.provider = getRialoProvider();\n this.setupEvents();\n }\n\n private setupEvents() {\n if (!this.provider) return;\n\n this.provider.on('disconnect', () => {\n this._connected = false;\n this._accounts = [];\n });\n\n this.provider.on('accountsChanged', (data: unknown) => {\n const accounts = data as WalletAccount[];\n this._accounts = accounts;\n });\n\n this.provider.on('networkChanged', (data: unknown) => {\n const { network } = data as { network: RialoNetwork };\n this._network = network;\n });\n }\n\n get isInstalled(): boolean {\n return isRialoInstalled();\n }\n\n get connected(): boolean {\n return this._connected;\n }\n\n get accounts(): WalletAccount[] {\n return this._accounts;\n }\n\n get activeAccount(): WalletAccount | undefined {\n return this._accounts[0];\n }\n\n get network(): RialoNetwork {\n return this._network;\n }\n\n get chainId(): string {\n return `rialo:${this._network}`;\n }\n\n async connect(): Promise<WalletAccount[]> {\n this.provider = getRialoProvider();\n if (!this.provider) {\n throw new Error('Rialo Wallet not installed. Download at https://rialo.io/wallet');\n }\n\n const accounts = await this.provider.connect();\n this._accounts = accounts;\n this._connected = true;\n\n const network = await this.provider.getNetwork();\n this._network = network;\n\n return this._accounts;\n }\n\n async disconnect(): Promise<void> {\n if (this.provider) {\n await this.provider.disconnect();\n }\n this._connected = false;\n this._accounts = [];\n }\n\n async signMessage(message: string): Promise<SignedMessage> {\n if (!this.provider || !this._connected) {\n throw new Error('Wallet not connected');\n }\n return this.provider.signMessage(message);\n }\n\n async signTransaction(tx: TransactionRequest): Promise<string> {\n if (!this.provider || !this._connected) {\n throw new Error('Wallet not connected');\n }\n const result = await this.provider.signTransaction(tx);\n return result.signature;\n }\n\n async sendTransaction(tx: TransactionRequest): Promise<TransactionResult> {\n if (!this.provider || !this._connected) {\n throw new Error('Wallet not connected');\n }\n return this.provider.sendTransaction(tx);\n }\n\n async signAndSendTransaction(tx: TransactionRequest): Promise<TransactionResult> {\n if (!this.provider || !this._connected) {\n throw new Error('Wallet not connected');\n }\n return this.provider.signAndSendTransaction(tx);\n }\n\n async getBalance(address?: string): Promise<string> {\n if (!this.provider) {\n throw new Error('Wallet not available');\n }\n const result = await this.provider.getBalance(address);\n if (typeof result === 'string') return result;\n return result.balance;\n }\n\n async switchNetwork(network: RialoNetwork): Promise<void> {\n if (!this.provider) {\n throw new Error('Wallet not available');\n }\n await this.provider.switchNetwork(network);\n this._network = network;\n }\n\n on(event: WalletEvent, callback: (data: unknown) => void): () => void {\n if (!this.provider) {\n return () => {};\n }\n return this.provider.on(event, callback);\n }\n}\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\nexport function formatAddress(address: string, chars = 4): string {\n if (!address) return '';\n if (address.length <= chars * 2 + 3) return address;\n return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;\n}\n\nexport function formatBalance(kelvins: string | bigint, decimals = 4): string {\n const value = typeof kelvins === 'string' ? BigInt(kelvins || '0') : kelvins;\n const rlo = Number(value) / 1_000_000_000;\n return rlo.toFixed(decimals);\n}\n\nexport function parseBalance(rlo: string | number): bigint {\n const value = typeof rlo === 'string' ? parseFloat(rlo) : rlo;\n return BigInt(Math.floor(value * 1_000_000_000));\n}\n\nexport function isValidAddress(address: string): boolean {\n if (!address || typeof address !== 'string') return false;\n if (address.length < 32 || address.length > 50) return false;\n return /^[1-9A-HJ-NP-Za-km-z]+$/.test(address);\n}\n\nexport function toChainId(network: RialoNetwork): RialoChain {\n return `rialo:${network}` as RialoChain;\n}\n\nexport function fromChainId(chainId: RialoChain): RialoNetwork {\n return chainId.replace('rialo:', '') as RialoNetwork;\n}\n\n// ============================================================================\n// Window Extension\n// ============================================================================\n\ninterface RialoWindow extends Window {\n rialo?: RialoProvider;\n}\n\ndeclare global {\n interface Window {\n rialo?: RialoProvider;\n Rialo?: RialoProvider;\n }\n}\n\n// ============================================================================\n// Exports\n// ============================================================================\n\nexport default RialoWallet;\n"]}
|