@cookill/wallet-adapter 0.1.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/LICENSE +21 -0
- package/README.md +369 -0
- package/dist/index.cjs +183 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +137 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.js +170 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +483 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +133 -0
- package/dist/react.d.ts +133 -0
- package/dist/react.js +465 -0
- package/dist/react.js.map +1 -0
- package/dist/standard.cjs +175 -0
- package/dist/standard.cjs.map +1 -0
- package/dist/standard.d.cts +134 -0
- package/dist/standard.d.ts +134 -0
- package/dist/standard.js +164 -0
- package/dist/standard.js.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Rialo Network
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
# @cookillabs/wallet-adapter
|
|
2
|
+
|
|
3
|
+
> ⚠️ **COMMUNITY PACKAGE DISCLAIMER**
|
|
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)
|
|
6
|
+
|
|
7
|
+
Universal wallet adapter for Rialo blockchain dApps. Connect to Rialo Wallet and other compatible wallets with a simple, unified API.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @cookillabs/wallet-adapter
|
|
13
|
+
# or
|
|
14
|
+
yarn add @cookillabs/wallet-adapter
|
|
15
|
+
# or
|
|
16
|
+
bun add @cookillabs/wallet-adapter
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### React (Recommended)
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { WalletProvider, ConnectButton, WalletModal, useWallet } from '@cookillabs/wallet-adapter/react';
|
|
25
|
+
|
|
26
|
+
function App() {
|
|
27
|
+
return (
|
|
28
|
+
<WalletProvider network="devnet" autoConnect>
|
|
29
|
+
<ConnectButton />
|
|
30
|
+
<WalletModal />
|
|
31
|
+
<YourDApp />
|
|
32
|
+
</WalletProvider>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function YourDApp() {
|
|
37
|
+
const { connected, activeAccount, signMessage, sendTransaction } = useWallet();
|
|
38
|
+
|
|
39
|
+
const handleSign = async () => {
|
|
40
|
+
const result = await signMessage('Hello Rialo!');
|
|
41
|
+
console.log('Signature:', result.signature);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const handleSend = async () => {
|
|
45
|
+
const result = await sendTransaction({
|
|
46
|
+
to: 'RecipientBase58Address...', // Base58 address
|
|
47
|
+
value: '1000000000', // 1 RLO in kelvins
|
|
48
|
+
});
|
|
49
|
+
console.log('TX Hash:', result.hash);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (!connected) return <p>Please connect your wallet</p>;
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div>
|
|
56
|
+
<p>Connected: {activeAccount?.address}</p>
|
|
57
|
+
<button onClick={handleSign}>Sign Message</button>
|
|
58
|
+
<button onClick={handleSend}>Send 1 RLO</button>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Vanilla JavaScript
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { RialoWallet, isRialoInstalled, formatBalance } from '@cookillabs/wallet-adapter';
|
|
68
|
+
|
|
69
|
+
const wallet = new RialoWallet();
|
|
70
|
+
|
|
71
|
+
// Check if installed
|
|
72
|
+
if (!isRialoInstalled()) {
|
|
73
|
+
console.log('Please install Rialo Wallet from https://rialo.io/wallet');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Connect
|
|
77
|
+
const accounts = await wallet.connect();
|
|
78
|
+
console.log('Connected:', accounts[0].address);
|
|
79
|
+
|
|
80
|
+
// Get balance
|
|
81
|
+
const balance = await wallet.getBalance();
|
|
82
|
+
console.log('Balance:', formatBalance(balance), 'RLO');
|
|
83
|
+
|
|
84
|
+
// Sign message
|
|
85
|
+
const signed = await wallet.signMessage('Hello Rialo!');
|
|
86
|
+
console.log('Signature:', signed.signature);
|
|
87
|
+
|
|
88
|
+
// Send transaction
|
|
89
|
+
const tx = await wallet.signAndSendTransaction({
|
|
90
|
+
to: 'RecipientBase58Address...', // Base58 address
|
|
91
|
+
value: '1000000000', // 1 RLO
|
|
92
|
+
});
|
|
93
|
+
console.log('TX Hash:', tx.hash);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Direct Provider Access
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
// Access the injected provider directly
|
|
100
|
+
if (window.rialo) {
|
|
101
|
+
const accounts = await window.rialo.connect();
|
|
102
|
+
const balance = await window.rialo.getBalance();
|
|
103
|
+
|
|
104
|
+
const tx = await window.rialo.signAndSendTransaction({
|
|
105
|
+
to: 'RecipientBase58Address...',
|
|
106
|
+
value: '1000000000',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## React Hooks
|
|
112
|
+
|
|
113
|
+
### useWallet
|
|
114
|
+
|
|
115
|
+
Main hook with all functionality:
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
const {
|
|
119
|
+
// State
|
|
120
|
+
connected, // boolean - connection status
|
|
121
|
+
connecting, // boolean - connection in progress
|
|
122
|
+
accounts, // WalletAccount[] - all accounts
|
|
123
|
+
activeAccount, // WalletAccount | null - current account
|
|
124
|
+
network, // 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
125
|
+
balance, // string | null - balance in kelvins
|
|
126
|
+
|
|
127
|
+
// Actions
|
|
128
|
+
connect, // () => Promise<WalletAccount[]>
|
|
129
|
+
disconnect, // () => Promise<void>
|
|
130
|
+
switchNetwork, // (network) => Promise<void>
|
|
131
|
+
|
|
132
|
+
// Transactions
|
|
133
|
+
signMessage, // (message: string) => Promise<SignedMessage>
|
|
134
|
+
signTransaction, // (tx) => Promise<string>
|
|
135
|
+
sendTransaction, // (tx) => Promise<TransactionResult>
|
|
136
|
+
signAndSendTransaction, // (tx) => Promise<TransactionResult>
|
|
137
|
+
|
|
138
|
+
// Modal
|
|
139
|
+
isModalOpen,
|
|
140
|
+
openModal,
|
|
141
|
+
closeModal,
|
|
142
|
+
} = useWallet();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Specialized Hooks
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
// Connection status
|
|
149
|
+
const connected = useIsConnected();
|
|
150
|
+
|
|
151
|
+
// Active account
|
|
152
|
+
const account = useActiveAccount();
|
|
153
|
+
|
|
154
|
+
// All accounts
|
|
155
|
+
const accounts = useAccounts();
|
|
156
|
+
|
|
157
|
+
// Balance
|
|
158
|
+
const { balance, formatted } = useBalance();
|
|
159
|
+
|
|
160
|
+
// Network
|
|
161
|
+
const { network, config } = useNetwork();
|
|
162
|
+
|
|
163
|
+
// Connect with loading state
|
|
164
|
+
const { connect, connecting, isInstalled } = useConnectWallet();
|
|
165
|
+
|
|
166
|
+
// Sign message with state
|
|
167
|
+
const { sign, signing, signature, error } = useSignMessage();
|
|
168
|
+
|
|
169
|
+
// Send transaction with state
|
|
170
|
+
const { send, sending, txHash, error } = useSendTransaction();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Components
|
|
174
|
+
|
|
175
|
+
### ConnectButton
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
<ConnectButton
|
|
179
|
+
connectLabel="Connect Wallet" // Button text
|
|
180
|
+
showAddress={true} // Show address when connected
|
|
181
|
+
className="my-button" // Custom class
|
|
182
|
+
style={{ ... }} // Custom styles
|
|
183
|
+
/>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### WalletModal
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
<WalletModal
|
|
190
|
+
title="Select Wallet" // Modal title
|
|
191
|
+
className="my-modal" // Custom class
|
|
192
|
+
/>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### WalletProvider
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
<WalletProvider
|
|
199
|
+
network="devnet" // Default network
|
|
200
|
+
autoConnect={true} // Auto-connect on mount
|
|
201
|
+
wallets={[customWallet]} // Additional wallets
|
|
202
|
+
onConnect={(accounts) => console.log('Connected', accounts)}
|
|
203
|
+
onDisconnect={() => console.log('Disconnected')}
|
|
204
|
+
onError={(error) => console.error(error)}
|
|
205
|
+
>
|
|
206
|
+
{children}
|
|
207
|
+
</WalletProvider>
|
|
208
|
+
```
|
|
209
|
+
|
|
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
|
+
## Wallet Standard
|
|
235
|
+
|
|
236
|
+
For advanced integrations using the Wallet Standard:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import {
|
|
240
|
+
RialoWalletStandard,
|
|
241
|
+
registerRialoWallet,
|
|
242
|
+
getRialoWallet,
|
|
243
|
+
RIALO_SIGN_MESSAGE,
|
|
244
|
+
RIALO_SIGN_TRANSACTION,
|
|
245
|
+
} from '@cookillabs/wallet-adapter/standard';
|
|
246
|
+
|
|
247
|
+
// Get registered wallet
|
|
248
|
+
const wallet = getRialoWallet();
|
|
249
|
+
|
|
250
|
+
if (wallet) {
|
|
251
|
+
// Connect
|
|
252
|
+
const { accounts } = await wallet.features['standard:connect'].connect();
|
|
253
|
+
|
|
254
|
+
// Sign message
|
|
255
|
+
const message = new TextEncoder().encode('Hello Rialo!');
|
|
256
|
+
const { signature } = await wallet.features[RIALO_SIGN_MESSAGE].signMessage({
|
|
257
|
+
account: accounts[0],
|
|
258
|
+
message,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// Listen for changes
|
|
262
|
+
const unsubscribe = wallet.features['standard:events'].on('change', (data) => {
|
|
263
|
+
console.log('Wallet changed:', data);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Address Format
|
|
269
|
+
|
|
270
|
+
Rialo uses **base58** encoded addresses (32-50 characters). Examples:
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
✅ Valid: 5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8
|
|
274
|
+
✅ Valid: 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin
|
|
275
|
+
❌ Invalid: rialo1abc123... (old format, no longer used)
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Networks
|
|
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 |
|
|
286
|
+
|
|
287
|
+
## Utility Functions
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import {
|
|
291
|
+
formatAddress, // (address, chars?) => "5YNmS...VWr8"
|
|
292
|
+
formatBalance, // (kelvins, decimals?) => "1.0000"
|
|
293
|
+
parseBalance, // (rlo) => bigint (kelvins)
|
|
294
|
+
isValidAddress, // (address) => boolean (base58 validation)
|
|
295
|
+
isRialoInstalled, // () => boolean
|
|
296
|
+
getRialoProvider, // () => RialoProvider | undefined
|
|
297
|
+
NETWORKS, // Network configurations
|
|
298
|
+
} from '@cookillabs/wallet-adapter';
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## TypeScript
|
|
302
|
+
|
|
303
|
+
Full TypeScript support included:
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
import type {
|
|
307
|
+
WalletAccount,
|
|
308
|
+
TransactionRequest,
|
|
309
|
+
TransactionResult,
|
|
310
|
+
SignedMessage,
|
|
311
|
+
NetworkConfig,
|
|
312
|
+
WalletInfo,
|
|
313
|
+
RialoProvider,
|
|
314
|
+
RialoNetwork,
|
|
315
|
+
RialoChain,
|
|
316
|
+
} from '@cookillabs/wallet-adapter';
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Building a Compatible Wallet
|
|
320
|
+
|
|
321
|
+
To make your wallet compatible with this adapter, inject a provider at `window.rialo`:
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
window.rialo = {
|
|
325
|
+
isRialo: true,
|
|
326
|
+
version: '1.0.0',
|
|
327
|
+
|
|
328
|
+
// Connection
|
|
329
|
+
connect: async () => ['5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8'],
|
|
330
|
+
disconnect: async () => {},
|
|
331
|
+
isConnected: async () => true,
|
|
332
|
+
getAccounts: async () => ['5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8'],
|
|
333
|
+
|
|
334
|
+
// Transactions - MUST use real signing via window.rialo provider
|
|
335
|
+
signTransaction: async (tx) => ({ signature: '...real signature...' }),
|
|
336
|
+
sendTransaction: async (tx) => ({ hash: '...real tx hash...', status: 'pending' }),
|
|
337
|
+
signAndSendTransaction: async (tx) => ({ hash: '...real tx hash...', status: 'pending' }),
|
|
338
|
+
|
|
339
|
+
// Message signing
|
|
340
|
+
signMessage: async (message) => ({
|
|
341
|
+
signature: '...real signature...',
|
|
342
|
+
message,
|
|
343
|
+
address: '5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8'
|
|
344
|
+
}),
|
|
345
|
+
|
|
346
|
+
// Network
|
|
347
|
+
getNetwork: async () => 'rialo:devnet',
|
|
348
|
+
switchNetwork: async (network) => {},
|
|
349
|
+
getBalance: async (address) => '1000000000',
|
|
350
|
+
|
|
351
|
+
// Events
|
|
352
|
+
on: (event, callback) => () => {},
|
|
353
|
+
removeListener: (event, callback) => {},
|
|
354
|
+
removeAllListeners: (event) => {},
|
|
355
|
+
};
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## Publishing to NPM
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
cd packages/wallet-adapter
|
|
362
|
+
npm install
|
|
363
|
+
npm run build
|
|
364
|
+
npm publish --access public
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## License
|
|
368
|
+
|
|
369
|
+
MIT © Cookillabs
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
var NETWORKS = {
|
|
7
|
+
mainnet: {
|
|
8
|
+
chainId: "rialo:mainnet",
|
|
9
|
+
name: "Rialo Mainnet",
|
|
10
|
+
rpcUrl: "https://mainnet.rialo.io:4101",
|
|
11
|
+
wsUrl: "wss://mainnet.rialo.io:4102",
|
|
12
|
+
explorerUrl: "https://explorer.rialo.io"
|
|
13
|
+
},
|
|
14
|
+
testnet: {
|
|
15
|
+
chainId: "rialo:testnet",
|
|
16
|
+
name: "Rialo Testnet",
|
|
17
|
+
rpcUrl: "https://testnet.rialo.io:4101",
|
|
18
|
+
wsUrl: "wss://testnet.rialo.io:4102",
|
|
19
|
+
explorerUrl: "https://testnet.explorer.rialo.io"
|
|
20
|
+
},
|
|
21
|
+
devnet: {
|
|
22
|
+
chainId: "rialo:devnet",
|
|
23
|
+
name: "Rialo Devnet",
|
|
24
|
+
rpcUrl: "https://devnet.rialo.io:4101",
|
|
25
|
+
wsUrl: "wss://devnet.rialo.io:4102",
|
|
26
|
+
explorerUrl: "https://devnet.explorer.rialo.io"
|
|
27
|
+
},
|
|
28
|
+
localnet: {
|
|
29
|
+
chainId: "rialo:localnet",
|
|
30
|
+
name: "Rialo Localnet",
|
|
31
|
+
rpcUrl: "http://localhost:4101",
|
|
32
|
+
wsUrl: "ws://localhost:4102",
|
|
33
|
+
explorerUrl: "http://localhost:3000"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function isRialoInstalled() {
|
|
37
|
+
if (typeof window === "undefined") return false;
|
|
38
|
+
return !!window.rialo?.isRialo;
|
|
39
|
+
}
|
|
40
|
+
function getRialoProvider() {
|
|
41
|
+
if (typeof window === "undefined") return void 0;
|
|
42
|
+
const rialo = window.rialo;
|
|
43
|
+
return rialo?.isRialo ? rialo : void 0;
|
|
44
|
+
}
|
|
45
|
+
function waitForRialoProvider(timeout = 3e3) {
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
if (isRialoInstalled()) {
|
|
48
|
+
resolve(getRialoProvider());
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const checkInterval = setInterval(() => {
|
|
52
|
+
if (isRialoInstalled()) {
|
|
53
|
+
clearInterval(checkInterval);
|
|
54
|
+
resolve(getRialoProvider());
|
|
55
|
+
}
|
|
56
|
+
}, 100);
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
clearInterval(checkInterval);
|
|
59
|
+
resolve(void 0);
|
|
60
|
+
}, timeout);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
var RialoWallet = class {
|
|
64
|
+
constructor() {
|
|
65
|
+
this._connected = false;
|
|
66
|
+
this._accounts = [];
|
|
67
|
+
this._network = "devnet";
|
|
68
|
+
this.provider = getRialoProvider();
|
|
69
|
+
}
|
|
70
|
+
get isInstalled() {
|
|
71
|
+
return isRialoInstalled();
|
|
72
|
+
}
|
|
73
|
+
get connected() {
|
|
74
|
+
return this._connected;
|
|
75
|
+
}
|
|
76
|
+
get accounts() {
|
|
77
|
+
return this._accounts;
|
|
78
|
+
}
|
|
79
|
+
get activeAccount() {
|
|
80
|
+
return this._accounts[0];
|
|
81
|
+
}
|
|
82
|
+
get network() {
|
|
83
|
+
return this._network;
|
|
84
|
+
}
|
|
85
|
+
async connect() {
|
|
86
|
+
this.provider = getRialoProvider();
|
|
87
|
+
if (!this.provider) {
|
|
88
|
+
throw new Error("Rialo Wallet not installed. Download at https://rialo.io/wallet");
|
|
89
|
+
}
|
|
90
|
+
const addresses = await this.provider.connect();
|
|
91
|
+
this._accounts = addresses.map((address) => ({ address }));
|
|
92
|
+
this._connected = true;
|
|
93
|
+
const networkStr = await this.provider.getNetwork();
|
|
94
|
+
this._network = networkStr.replace("rialo:", "");
|
|
95
|
+
return this._accounts;
|
|
96
|
+
}
|
|
97
|
+
async disconnect() {
|
|
98
|
+
if (this.provider) {
|
|
99
|
+
await this.provider.disconnect();
|
|
100
|
+
}
|
|
101
|
+
this._connected = false;
|
|
102
|
+
this._accounts = [];
|
|
103
|
+
}
|
|
104
|
+
async signMessage(message) {
|
|
105
|
+
if (!this.provider || !this._connected) {
|
|
106
|
+
throw new Error("Wallet not connected");
|
|
107
|
+
}
|
|
108
|
+
return this.provider.signMessage(message);
|
|
109
|
+
}
|
|
110
|
+
async signTransaction(tx) {
|
|
111
|
+
if (!this.provider || !this._connected) {
|
|
112
|
+
throw new Error("Wallet not connected");
|
|
113
|
+
}
|
|
114
|
+
const result = await this.provider.signTransaction(tx);
|
|
115
|
+
return result.signature;
|
|
116
|
+
}
|
|
117
|
+
async sendTransaction(tx) {
|
|
118
|
+
if (!this.provider || !this._connected) {
|
|
119
|
+
throw new Error("Wallet not connected");
|
|
120
|
+
}
|
|
121
|
+
return this.provider.sendTransaction(tx);
|
|
122
|
+
}
|
|
123
|
+
async signAndSendTransaction(tx) {
|
|
124
|
+
if (!this.provider || !this._connected) {
|
|
125
|
+
throw new Error("Wallet not connected");
|
|
126
|
+
}
|
|
127
|
+
return this.provider.signAndSendTransaction(tx);
|
|
128
|
+
}
|
|
129
|
+
async getBalance(address) {
|
|
130
|
+
if (!this.provider) {
|
|
131
|
+
throw new Error("Wallet not available");
|
|
132
|
+
}
|
|
133
|
+
return this.provider.getBalance(address);
|
|
134
|
+
}
|
|
135
|
+
async switchNetwork(network) {
|
|
136
|
+
if (!this.provider) {
|
|
137
|
+
throw new Error("Wallet not available");
|
|
138
|
+
}
|
|
139
|
+
await this.provider.switchNetwork(network);
|
|
140
|
+
this._network = network;
|
|
141
|
+
}
|
|
142
|
+
on(event, callback) {
|
|
143
|
+
if (!this.provider) {
|
|
144
|
+
return () => {
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return this.provider.on(event, callback);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
function formatAddress(address, chars = 4) {
|
|
151
|
+
if (!address) return "";
|
|
152
|
+
if (address.length <= chars * 2 + 3) return address;
|
|
153
|
+
return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
|
|
154
|
+
}
|
|
155
|
+
function formatBalance(kelvins, decimals = 4) {
|
|
156
|
+
const value = typeof kelvins === "string" ? BigInt(kelvins) : kelvins;
|
|
157
|
+
const rlo = Number(value) / 1e9;
|
|
158
|
+
return rlo.toFixed(decimals);
|
|
159
|
+
}
|
|
160
|
+
function parseBalance(rlo) {
|
|
161
|
+
const value = typeof rlo === "string" ? parseFloat(rlo) : rlo;
|
|
162
|
+
return BigInt(Math.floor(value * 1e9));
|
|
163
|
+
}
|
|
164
|
+
function isValidAddress(address) {
|
|
165
|
+
if (!address || typeof address !== "string") return false;
|
|
166
|
+
if (address.length < 32 || address.length > 50) return false;
|
|
167
|
+
const base58Regex = /^[1-9A-HJ-NP-Za-km-z]+$/;
|
|
168
|
+
return base58Regex.test(address);
|
|
169
|
+
}
|
|
170
|
+
var src_default = RialoWallet;
|
|
171
|
+
|
|
172
|
+
exports.NETWORKS = NETWORKS;
|
|
173
|
+
exports.RialoWallet = RialoWallet;
|
|
174
|
+
exports.default = src_default;
|
|
175
|
+
exports.formatAddress = formatAddress;
|
|
176
|
+
exports.formatBalance = formatBalance;
|
|
177
|
+
exports.getRialoProvider = getRialoProvider;
|
|
178
|
+
exports.isRialoInstalled = isRialoInstalled;
|
|
179
|
+
exports.isValidAddress = isValidAddress;
|
|
180
|
+
exports.parseBalance = parseBalance;
|
|
181
|
+
exports.waitForRialoProvider = waitForRialoProvider;
|
|
182
|
+
//# sourceMappingURL=index.cjs.map
|
|
183
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAwEO,IAAM,QAAA,GAAgD;AAAA,EAC3D,OAAA,EAAS;AAAA,IACP,OAAA,EAAS,eAAA;AAAA,IACT,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,+BAAA;AAAA,IACR,KAAA,EAAO,6BAAA;AAAA,IACP,WAAA,EAAa;AAAA,GACf;AAAA,EACA,OAAA,EAAS;AAAA,IACP,OAAA,EAAS,eAAA;AAAA,IACT,IAAA,EAAM,eAAA;AAAA,IACN,MAAA,EAAQ,+BAAA;AAAA,IACR,KAAA,EAAO,6BAAA;AAAA,IACP,WAAA,EAAa;AAAA,GACf;AAAA,EACA,MAAA,EAAQ;AAAA,IACN,OAAA,EAAS,cAAA;AAAA,IACT,IAAA,EAAM,cAAA;AAAA,IACN,MAAA,EAAQ,8BAAA;AAAA,IACR,KAAA,EAAO,4BAAA;AAAA,IACP,WAAA,EAAa;AAAA,GACf;AAAA,EACA,QAAA,EAAU;AAAA,IACR,OAAA,EAAS,gBAAA;AAAA,IACT,IAAA,EAAM,gBAAA;AAAA,IACN,MAAA,EAAQ,uBAAA;AAAA,IACR,KAAA,EAAO,qBAAA;AAAA,IACP,WAAA,EAAa;AAAA;AAEjB;AA8CO,SAAS,gBAAA,GAA4B;AA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jD;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"]}
|