stellar-wallet-kit 2.0.2 β 2.0.5
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 +83 -119
- package/dist/index.d.mts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +417 -366
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +417 -368
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -5
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# π Stellar Wallet Kit
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
Built with TypeScript
|
|
3
|
+
A **production-ready wallet connection SDK** for Stellar dApps.
|
|
4
|
+
Built with **TypeScript + React**, inspired by RainbowKit β but designed for the **realities of Stellar wallets**.
|
|
5
5
|
|
|
6
6
|
[](https://www.npmjs.com/package/stellar-wallet-kit)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -11,17 +11,21 @@ Built with TypeScript and React, inspired by RainbowKit.
|
|
|
11
11
|
|
|
12
12
|
## β¨ Features
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
* π **Multiple Wallets**
|
|
15
|
+
|
|
16
|
+
* Freighter (extension)
|
|
17
|
+
* Albedo (web popup)
|
|
18
|
+
* WalletConnect (mobile wallets)
|
|
19
|
+
* LOBSTR (via WalletConnect)
|
|
20
|
+
* π¨ **Customizable Wallet Modal**
|
|
21
|
+
* β‘ **TypeScript-first**
|
|
22
|
+
* π― **React Hooks API**
|
|
23
|
+
* π° **Built-in balance fetching**
|
|
24
|
+
* πΎ **Session persistence**
|
|
25
|
+
* π **Light / Dark / Auto theme**
|
|
26
|
+
* π **Auto-refresh balances**
|
|
27
|
+
* π± **Next.js (App Router & Pages) compatible**
|
|
28
|
+
* π **Framework-agnostic core**
|
|
25
29
|
|
|
26
30
|
---
|
|
27
31
|
|
|
@@ -33,7 +37,7 @@ npm install stellar-wallet-kit
|
|
|
33
37
|
yarn add stellar-wallet-kit
|
|
34
38
|
# or
|
|
35
39
|
pnpm add stellar-wallet-kit
|
|
36
|
-
|
|
40
|
+
```
|
|
37
41
|
|
|
38
42
|
---
|
|
39
43
|
|
|
@@ -66,7 +70,7 @@ export function App() {
|
|
|
66
70
|
import { ConnectButton } from 'stellar-wallet-kit';
|
|
67
71
|
|
|
68
72
|
export function Header() {
|
|
69
|
-
return <ConnectButton
|
|
73
|
+
return <ConnectButton />;
|
|
70
74
|
}
|
|
71
75
|
```
|
|
72
76
|
|
|
@@ -80,9 +84,7 @@ import { useWallet } from 'stellar-wallet-kit';
|
|
|
80
84
|
function Dashboard() {
|
|
81
85
|
const { account, isConnected, signTransaction } = useWallet();
|
|
82
86
|
|
|
83
|
-
if (!isConnected)
|
|
84
|
-
return <p>Please connect your wallet</p>;
|
|
85
|
-
}
|
|
87
|
+
if (!isConnected) return <p>Please connect your wallet</p>;
|
|
86
88
|
|
|
87
89
|
return (
|
|
88
90
|
<div>
|
|
@@ -99,72 +101,70 @@ function Dashboard() {
|
|
|
99
101
|
|
|
100
102
|
## π Supported Wallets
|
|
101
103
|
|
|
102
|
-
| Wallet
|
|
103
|
-
|
|
|
104
|
-
| **Freighter**
|
|
105
|
-
| **Albedo**
|
|
104
|
+
| Wallet | Type | Connection Model | Auto-Reconnect |
|
|
105
|
+
| ----------------- | ----------------- | ---------------------- | -------------- |
|
|
106
|
+
| **Freighter** | Browser extension | Injected API | β
|
|
|
107
|
+
| **Albedo** | Web wallet | Popup + callback | β |
|
|
108
|
+
| **WalletConnect** | Mobile wallets | QR / deep-link session | β
|
|
|
109
|
+
| **LOBSTR** | Mobile wallet | WalletConnect | β
|
|
|
110
|
+
|
|
111
|
+
> **LOBSTR is exposed separately in the UI** but internally uses WalletConnect.
|
|
106
112
|
|
|
107
113
|
---
|
|
108
114
|
|
|
109
|
-
##
|
|
115
|
+
## π WalletConnect & LOBSTR (Important)
|
|
110
116
|
|
|
111
|
-
|
|
117
|
+
WalletConnect **does not block the UI** like extensions.
|
|
112
118
|
|
|
113
|
-
|
|
119
|
+
* QR modal stays visible
|
|
120
|
+
* SDK tracks `connectingWallet`
|
|
121
|
+
* Global loaders **do not cover** WalletConnect
|
|
114
122
|
|
|
115
|
-
This
|
|
123
|
+
This avoids the βQR hidden behind loaderβ problem by design.
|
|
116
124
|
|
|
117
125
|
---
|
|
118
126
|
|
|
119
|
-
###
|
|
127
|
+
### Connecting explicitly
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
import { WalletType, useWallet } from 'stellar-wallet-kit';
|
|
120
131
|
|
|
121
|
-
|
|
122
|
-
2. User approves the action in Albedo
|
|
123
|
-
3. Albedo redirects the popup to a callback URL
|
|
124
|
-
4. The callback sends data back to your app
|
|
125
|
-
5. The popup closes and the wallet is connected
|
|
132
|
+
const { connect } = useWallet();
|
|
126
133
|
|
|
127
|
-
|
|
134
|
+
await connect(WalletType.WALLETCONNECT);
|
|
135
|
+
await connect(WalletType.LOBSTR);
|
|
136
|
+
```
|
|
128
137
|
|
|
129
138
|
---
|
|
130
139
|
|
|
131
|
-
##
|
|
140
|
+
## π Albedo Wallet Integration (Required)
|
|
132
141
|
|
|
133
|
-
|
|
142
|
+
Albedo is a **web-based wallet** and **requires a callback route**.
|
|
134
143
|
|
|
135
|
-
|
|
144
|
+
If the callback is missing:
|
|
136
145
|
|
|
137
|
-
|
|
146
|
+
* Albedo opens
|
|
147
|
+
* User approves
|
|
148
|
+
* **Connection never completes**
|
|
138
149
|
|
|
139
|
-
|
|
150
|
+
This is expected behavior.
|
|
140
151
|
|
|
141
|
-
|
|
142
|
-
// pages/albedo-callback.tsx
|
|
143
|
-
import { useEffect } from 'react';
|
|
144
|
-
|
|
145
|
-
export default function AlbedoCallback() {
|
|
146
|
-
useEffect(() => {
|
|
147
|
-
const params = Object.fromEntries(
|
|
148
|
-
new URLSearchParams(window.location.search)
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
if (window.opener) {
|
|
152
|
-
window.opener.postMessage(
|
|
153
|
-
{ type: 'ALBEDO_RESULT', payload: params },
|
|
154
|
-
window.location.origin
|
|
155
|
-
);
|
|
156
|
-
}
|
|
152
|
+
---
|
|
157
153
|
|
|
158
|
-
|
|
159
|
-
}, []);
|
|
154
|
+
### How Albedo Works
|
|
160
155
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
156
|
+
1. App opens Albedo popup
|
|
157
|
+
2. User approves
|
|
158
|
+
3. Albedo redirects to callback URL
|
|
159
|
+
4. Callback posts message to opener
|
|
160
|
+
5. Popup closes
|
|
161
|
+
6. Wallet connects
|
|
164
162
|
|
|
165
163
|
---
|
|
166
164
|
|
|
167
|
-
###
|
|
165
|
+
### Required: Add a Callback Route
|
|
166
|
+
|
|
167
|
+
#### Next.js (App Router)
|
|
168
168
|
|
|
169
169
|
```tsx
|
|
170
170
|
// app/albedo-callback/page.tsx
|
|
@@ -194,43 +194,6 @@ export default function AlbedoCallback() {
|
|
|
194
194
|
|
|
195
195
|
---
|
|
196
196
|
|
|
197
|
-
### Example: React Router
|
|
198
|
-
|
|
199
|
-
```tsx
|
|
200
|
-
function AlbedoCallback() {
|
|
201
|
-
useEffect(() => {
|
|
202
|
-
const params = Object.fromEntries(
|
|
203
|
-
new URLSearchParams(window.location.search)
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
if (window.opener) {
|
|
207
|
-
window.opener.postMessage(
|
|
208
|
-
{ type: 'ALBEDO_RESULT', payload: params },
|
|
209
|
-
window.location.origin
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
window.close();
|
|
214
|
-
}, []);
|
|
215
|
-
|
|
216
|
-
return <p>Connecting walletβ¦</p>;
|
|
217
|
-
}
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
---
|
|
221
|
-
|
|
222
|
-
## π Connecting Explicitly to Albedo
|
|
223
|
-
|
|
224
|
-
```tsx
|
|
225
|
-
import { WalletType, useWallet } from 'stellar-wallet-kit';
|
|
226
|
-
|
|
227
|
-
const { connect } = useWallet();
|
|
228
|
-
|
|
229
|
-
await connect(WalletType.ALBEDO);
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
197
|
## π° Balance Utilities
|
|
235
198
|
|
|
236
199
|
```tsx
|
|
@@ -267,11 +230,12 @@ const usdc = getAssetBalance(account.balances, 'USDC', issuer);
|
|
|
267
230
|
|
|
268
231
|
## π― `useWallet()` API
|
|
269
232
|
|
|
270
|
-
```
|
|
233
|
+
```ts
|
|
271
234
|
const {
|
|
272
235
|
account,
|
|
273
236
|
isConnected,
|
|
274
237
|
isConnecting,
|
|
238
|
+
connectingWallet,
|
|
275
239
|
error,
|
|
276
240
|
network,
|
|
277
241
|
selectedWallet,
|
|
@@ -300,27 +264,27 @@ supports = {
|
|
|
300
264
|
}
|
|
301
265
|
```
|
|
302
266
|
|
|
303
|
-
|
|
267
|
+
Use this to:
|
|
268
|
+
|
|
269
|
+
* Disable unsupported actions
|
|
270
|
+
* Adjust UX per wallet
|
|
304
271
|
|
|
305
272
|
---
|
|
306
273
|
|
|
307
|
-
##
|
|
274
|
+
## π Troubleshooting
|
|
308
275
|
|
|
309
|
-
|
|
310
|
-
'use client';
|
|
276
|
+
### WalletConnect QR stuck on βConnectingβ¦β
|
|
311
277
|
|
|
312
|
-
|
|
278
|
+
β Mobile wallet not approved
|
|
279
|
+
β App not foregrounded on phone
|
|
280
|
+
β Session rejected in wallet
|
|
313
281
|
|
|
314
|
-
|
|
315
|
-
return <WalletProvider>{children}</WalletProvider>;
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
---
|
|
282
|
+
### QR hidden behind loader
|
|
320
283
|
|
|
321
|
-
|
|
284
|
+
β **Handled automatically**
|
|
285
|
+
WalletConnect never blocks UI
|
|
322
286
|
|
|
323
|
-
### Albedo
|
|
287
|
+
### Albedo opens but doesnβt connect
|
|
324
288
|
|
|
325
289
|
β Missing callback route
|
|
326
290
|
β Callback URL mismatch
|
|
@@ -328,31 +292,31 @@ export function Providers({ children }) {
|
|
|
328
292
|
|
|
329
293
|
### Freighter not detected
|
|
330
294
|
|
|
331
|
-
β
|
|
295
|
+
β Extension not installed / disabled
|
|
332
296
|
|
|
333
297
|
---
|
|
334
298
|
|
|
335
299
|
## πΊοΈ Roadmap
|
|
336
300
|
|
|
337
|
-
* [x] Freighter
|
|
338
|
-
* [x] Albedo
|
|
339
|
-
* [x]
|
|
301
|
+
* [x] Freighter
|
|
302
|
+
* [x] Albedo
|
|
303
|
+
* [x] WalletConnect
|
|
304
|
+
* [x] LOBSTR
|
|
340
305
|
* [ ] xBull
|
|
341
306
|
* [ ] Rabet
|
|
342
|
-
* [ ]
|
|
343
|
-
* [ ] Mobile deep-link wallets
|
|
307
|
+
* [ ] Multi-account support
|
|
344
308
|
* [ ] Hardware wallets
|
|
345
309
|
|
|
346
310
|
---
|
|
347
311
|
|
|
348
312
|
## π License
|
|
349
313
|
|
|
350
|
-
MIT Β© Tushar Pamnani
|
|
314
|
+
MIT Β© **Tushar Pamnani**
|
|
351
315
|
|
|
352
316
|
---
|
|
353
317
|
|
|
354
318
|
## π Show Your Support
|
|
355
319
|
|
|
356
|
-
If this
|
|
320
|
+
If this SDK saved you pain β βοΈ it on GitHub.
|
|
357
321
|
|
|
358
322
|
Built with β€οΈ for the Stellar ecosystem.
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,9 @@ import React, { PropsWithChildren } from 'react';
|
|
|
2
2
|
|
|
3
3
|
declare enum WalletType {
|
|
4
4
|
FREIGHTER = "freighter",
|
|
5
|
-
ALBEDO = "albedo"
|
|
5
|
+
ALBEDO = "albedo",
|
|
6
|
+
WALLETCONNECT = "walletconnect",
|
|
7
|
+
LOBSTR = "lobstr"
|
|
6
8
|
}
|
|
7
9
|
declare enum NetworkType {
|
|
8
10
|
PUBLIC = "PUBLIC",
|
|
@@ -82,6 +84,7 @@ interface StellarWalletKitConfig {
|
|
|
82
84
|
theme?: WalletTheme;
|
|
83
85
|
appName?: string;
|
|
84
86
|
appIcon?: string;
|
|
87
|
+
adapters?: Partial<Record<WalletType, WalletAdapter>>;
|
|
85
88
|
}
|
|
86
89
|
interface WalletTheme {
|
|
87
90
|
mode?: "light" | "dark" | "auto";
|
|
@@ -123,8 +126,14 @@ interface WalletContextValue {
|
|
|
123
126
|
networkDetection: boolean;
|
|
124
127
|
authEntrySigning: boolean;
|
|
125
128
|
};
|
|
129
|
+
connectingWallet: WalletType | null;
|
|
126
130
|
}
|
|
127
131
|
type WalletKind = "extension" | "web";
|
|
132
|
+
interface WalletCapabilities {
|
|
133
|
+
silentReconnect: boolean;
|
|
134
|
+
networkDetection: boolean;
|
|
135
|
+
authEntrySigning: boolean;
|
|
136
|
+
}
|
|
128
137
|
|
|
129
138
|
type WalletProviderProps = PropsWithChildren<{
|
|
130
139
|
config?: StellarWalletKitConfig;
|
|
@@ -175,6 +184,10 @@ declare function getTotalValueXLM(balances: AccountBalance[]): string;
|
|
|
175
184
|
*/
|
|
176
185
|
declare function groupBalancesByType(balances: AccountBalance[]): Record<string, AccountBalance[]>;
|
|
177
186
|
|
|
187
|
+
declare function createWalletAdapters(config: {
|
|
188
|
+
walletConnectProjectId?: string;
|
|
189
|
+
}): Partial<Record<WalletType, WalletAdapter>>;
|
|
190
|
+
|
|
178
191
|
declare class FreighterAdapter implements WalletAdapter {
|
|
179
192
|
readonly type = WalletType.FREIGHTER;
|
|
180
193
|
isAvailable(): Promise<boolean>;
|
|
@@ -186,4 +199,20 @@ declare class FreighterAdapter implements WalletAdapter {
|
|
|
186
199
|
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
187
200
|
}
|
|
188
201
|
|
|
189
|
-
|
|
202
|
+
declare class WalletConnectAdapter implements WalletAdapter {
|
|
203
|
+
readonly type = WalletType.WALLETCONNECT;
|
|
204
|
+
private projectId;
|
|
205
|
+
private connector;
|
|
206
|
+
private session;
|
|
207
|
+
constructor(projectId: string);
|
|
208
|
+
isAvailable(): Promise<boolean>;
|
|
209
|
+
private getConnector;
|
|
210
|
+
connect(): Promise<ConnectWalletResponse>;
|
|
211
|
+
disconnect(): Promise<void>;
|
|
212
|
+
getPublicKey(): Promise<string | null>;
|
|
213
|
+
getNetwork(): Promise<string>;
|
|
214
|
+
signTransaction(xdr: string, _options?: SignTransactionOptions): Promise<SignTransactionResponse>;
|
|
215
|
+
signAuthEntry(_entryXdr: string, _options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { type AccountBalance, ConnectButton, type ConnectWalletResponse, FreighterAdapter, type ModalProps, NetworkType, type SignAuthEntryOptions, type SignAuthEntryResponse, type SignTransactionOptions, type SignTransactionResponse, type StellarWalletKitConfig, type WalletAccount, type WalletAdapter, type WalletCapabilities, WalletConnectAdapter, type WalletContextValue, type WalletInfo, type WalletKind, WalletModal, WalletProvider, type WalletTheme, WalletType, createWalletAdapters, fetchAccountBalances, formatBalance, getAssetBalance, getNativeBalance, getTotalValueXLM, groupBalancesByType, hasSufficientBalance, useWallet };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import React, { PropsWithChildren } from 'react';
|
|
|
2
2
|
|
|
3
3
|
declare enum WalletType {
|
|
4
4
|
FREIGHTER = "freighter",
|
|
5
|
-
ALBEDO = "albedo"
|
|
5
|
+
ALBEDO = "albedo",
|
|
6
|
+
WALLETCONNECT = "walletconnect",
|
|
7
|
+
LOBSTR = "lobstr"
|
|
6
8
|
}
|
|
7
9
|
declare enum NetworkType {
|
|
8
10
|
PUBLIC = "PUBLIC",
|
|
@@ -82,6 +84,7 @@ interface StellarWalletKitConfig {
|
|
|
82
84
|
theme?: WalletTheme;
|
|
83
85
|
appName?: string;
|
|
84
86
|
appIcon?: string;
|
|
87
|
+
adapters?: Partial<Record<WalletType, WalletAdapter>>;
|
|
85
88
|
}
|
|
86
89
|
interface WalletTheme {
|
|
87
90
|
mode?: "light" | "dark" | "auto";
|
|
@@ -123,8 +126,14 @@ interface WalletContextValue {
|
|
|
123
126
|
networkDetection: boolean;
|
|
124
127
|
authEntrySigning: boolean;
|
|
125
128
|
};
|
|
129
|
+
connectingWallet: WalletType | null;
|
|
126
130
|
}
|
|
127
131
|
type WalletKind = "extension" | "web";
|
|
132
|
+
interface WalletCapabilities {
|
|
133
|
+
silentReconnect: boolean;
|
|
134
|
+
networkDetection: boolean;
|
|
135
|
+
authEntrySigning: boolean;
|
|
136
|
+
}
|
|
128
137
|
|
|
129
138
|
type WalletProviderProps = PropsWithChildren<{
|
|
130
139
|
config?: StellarWalletKitConfig;
|
|
@@ -175,6 +184,10 @@ declare function getTotalValueXLM(balances: AccountBalance[]): string;
|
|
|
175
184
|
*/
|
|
176
185
|
declare function groupBalancesByType(balances: AccountBalance[]): Record<string, AccountBalance[]>;
|
|
177
186
|
|
|
187
|
+
declare function createWalletAdapters(config: {
|
|
188
|
+
walletConnectProjectId?: string;
|
|
189
|
+
}): Partial<Record<WalletType, WalletAdapter>>;
|
|
190
|
+
|
|
178
191
|
declare class FreighterAdapter implements WalletAdapter {
|
|
179
192
|
readonly type = WalletType.FREIGHTER;
|
|
180
193
|
isAvailable(): Promise<boolean>;
|
|
@@ -186,4 +199,20 @@ declare class FreighterAdapter implements WalletAdapter {
|
|
|
186
199
|
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
187
200
|
}
|
|
188
201
|
|
|
189
|
-
|
|
202
|
+
declare class WalletConnectAdapter implements WalletAdapter {
|
|
203
|
+
readonly type = WalletType.WALLETCONNECT;
|
|
204
|
+
private projectId;
|
|
205
|
+
private connector;
|
|
206
|
+
private session;
|
|
207
|
+
constructor(projectId: string);
|
|
208
|
+
isAvailable(): Promise<boolean>;
|
|
209
|
+
private getConnector;
|
|
210
|
+
connect(): Promise<ConnectWalletResponse>;
|
|
211
|
+
disconnect(): Promise<void>;
|
|
212
|
+
getPublicKey(): Promise<string | null>;
|
|
213
|
+
getNetwork(): Promise<string>;
|
|
214
|
+
signTransaction(xdr: string, _options?: SignTransactionOptions): Promise<SignTransactionResponse>;
|
|
215
|
+
signAuthEntry(_entryXdr: string, _options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { type AccountBalance, ConnectButton, type ConnectWalletResponse, FreighterAdapter, type ModalProps, NetworkType, type SignAuthEntryOptions, type SignAuthEntryResponse, type SignTransactionOptions, type SignTransactionResponse, type StellarWalletKitConfig, type WalletAccount, type WalletAdapter, type WalletCapabilities, WalletConnectAdapter, type WalletContextValue, type WalletInfo, type WalletKind, WalletModal, WalletProvider, type WalletTheme, WalletType, createWalletAdapters, fetchAccountBalances, formatBalance, getAssetBalance, getNativeBalance, getTotalValueXLM, groupBalancesByType, hasSufficientBalance, useWallet };
|