@pollar/stellar-wallets-kit-adapter 0.7.0 → 0.8.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 +129 -28
- package/dist/factory-D58ktBBa.d.mts +74 -0
- package/dist/factory-D58ktBBa.d.ts +74 -0
- package/dist/index.d.mts +4 -41
- package/dist/index.d.ts +4 -41
- package/dist/index.js +63 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -36
- package/dist/index.mjs.map +1 -1
- package/dist/picker.d.mts +45 -0
- package/dist/picker.d.ts +45 -0
- package/dist/picker.js +265 -0
- package/dist/picker.js.map +1 -0
- package/dist/picker.mjs +262 -0
- package/dist/picker.mjs.map +1 -0
- package/package.json +29 -2
package/README.md
CHANGED
|
@@ -36,35 +36,45 @@ import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
|
36
36
|
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
37
37
|
|
|
38
38
|
<PollarProvider
|
|
39
|
-
|
|
39
|
+
client={{
|
|
40
40
|
apiKey: 'your-api-key',
|
|
41
41
|
walletAdapter: stellarWalletsKit({ network: Networks.TESTNET }),
|
|
42
42
|
}}
|
|
43
43
|
>
|
|
44
44
|
{/* your app */}
|
|
45
|
-
</PollarProvider
|
|
45
|
+
</PollarProvider>;
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
This wires the **signing path** but the built-in `LoginModal` still shows
|
|
49
|
+
only Freighter / Albedo. To render the kit's full wallet list (xBull, Lobstr,
|
|
50
|
+
Rabet, …) inside `LoginModal`, also pass the picker — see
|
|
51
|
+
[Wallet picker UI (`/picker`)](#wallet-picker-ui-picker) below.
|
|
52
|
+
|
|
48
53
|
The kit is a global singleton. `stellarWalletsKit(...)` returns a resolver and `StellarWalletsKit.init(...)` is called once on the first `loginWallet` call.
|
|
49
54
|
|
|
55
|
+
> **0.8.0** — `network` is **required**. The previous `Networks.TESTNET`
|
|
56
|
+
> default was removed because the kit is a global singleton, and silently
|
|
57
|
+
> picking testnet for the consumer risked signing real-looking transactions
|
|
58
|
+
> on the wrong chain. Pass `Networks.TESTNET` or `Networks.PUBLIC` explicitly.
|
|
59
|
+
|
|
50
60
|
## Default wallets
|
|
51
61
|
|
|
52
|
-
Calling `stellarWalletsKit()` with no `modules` argument enables every module that loads without extra configuration:
|
|
53
|
-
|
|
54
|
-
| Module
|
|
55
|
-
|
|
|
56
|
-
| `AlbedoModule`
|
|
57
|
-
| `BitgetModule`
|
|
58
|
-
| `CactusLinkModule` | `cactuslink`
|
|
59
|
-
| `FordefiModule`
|
|
60
|
-
| `FreighterModule`
|
|
61
|
-
| `HanaModule`
|
|
62
|
-
| `HotWalletModule`
|
|
63
|
-
| `KleverModule`
|
|
64
|
-
| `LobstrModule`
|
|
65
|
-
| `OneKeyModule`
|
|
66
|
-
| `RabetModule`
|
|
67
|
-
| `xBullModule`
|
|
62
|
+
Calling `stellarWalletsKit({ network })` with no `modules` argument enables every module that loads without extra configuration:
|
|
63
|
+
|
|
64
|
+
| Module | Wallet id (`WalletId`) | Type |
|
|
65
|
+
| ------------------ | ---------------------- | ------------------ |
|
|
66
|
+
| `AlbedoModule` | `albedo` | Web |
|
|
67
|
+
| `BitgetModule` | `bitget` | Browser extension |
|
|
68
|
+
| `CactusLinkModule` | `cactuslink` | Browser extension |
|
|
69
|
+
| `FordefiModule` | `fordefi` | Browser extension |
|
|
70
|
+
| `FreighterModule` | `freighter` | Browser extension |
|
|
71
|
+
| `HanaModule` | `hana` | Browser extension |
|
|
72
|
+
| `HotWalletModule` | `hotwallet` | Mobile / deep link |
|
|
73
|
+
| `KleverModule` | `klever` | Browser extension |
|
|
74
|
+
| `LobstrModule` | `lobstr` | Mobile / deep link |
|
|
75
|
+
| `OneKeyModule` | `onekey` | Browser extension |
|
|
76
|
+
| `RabetModule` | `rabet` | Browser extension |
|
|
77
|
+
| `xBullModule` | `xbull` | Browser extension |
|
|
68
78
|
|
|
69
79
|
> **Why not Ledger / Trezor / WalletConnect by default?** Ledger needs a `Buffer` polyfill in the host app (loading it unconditionally would crash bundles that don't ship one). Trezor and WalletConnect require constructor parameters (Trezor manifest, WalletConnect project id). All three stay opt-in.
|
|
70
80
|
|
|
@@ -106,8 +116,12 @@ Trimming the default list (e.g. only Freighter + Albedo for a SEP-43 dapp) works
|
|
|
106
116
|
|
|
107
117
|
```ts
|
|
108
118
|
interface StellarWalletsKitAdapterOptions {
|
|
109
|
-
/**
|
|
110
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Stellar network used for signing. **Required** as of 0.8.0 — the kit is a
|
|
121
|
+
* global singleton, so the network must be chosen explicitly to avoid
|
|
122
|
+
* cross-chain signing accidents.
|
|
123
|
+
*/
|
|
124
|
+
network: Networks;
|
|
111
125
|
|
|
112
126
|
/**
|
|
113
127
|
* Wallet modules the kit can drive. Defaults to every module that works
|
|
@@ -115,6 +129,28 @@ interface StellarWalletsKitAdapterOptions {
|
|
|
115
129
|
* replaces the default — include modules you want explicitly.
|
|
116
130
|
*/
|
|
117
131
|
modules?: ModuleInterface[];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Picker-specific options. Only consumed by `<KitWalletPicker>` /
|
|
135
|
+
* `createStellarWalletsKitBundle` (the `/picker` subpath). The resolver
|
|
136
|
+
* itself ignores them.
|
|
137
|
+
*/
|
|
138
|
+
picker?: KitPickerOptions;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface KitPickerOptions {
|
|
142
|
+
/** Subset of wallet ids to show. Defaults to every wallet the kit reports. */
|
|
143
|
+
wallets?: string[];
|
|
144
|
+
/** Render order. Default `'as-given'` (the kit's own order). */
|
|
145
|
+
order?: 'as-given' | 'installed-first' | 'alphabetical';
|
|
146
|
+
/** Hide wallets whose `isAvailable` is false. Default `false`. */
|
|
147
|
+
showInstalledOnly?: boolean;
|
|
148
|
+
/** Per-wallet label overrides. Key = wallet id. */
|
|
149
|
+
labels?: Record<string, string>;
|
|
150
|
+
/** Visual layout. Default `'grid'`. */
|
|
151
|
+
layout?: 'grid' | 'list';
|
|
152
|
+
/** Theme passthrough — applied as CSS custom properties on the picker root. */
|
|
153
|
+
theme?: { accent?: string; mode?: 'light' | 'dark' };
|
|
118
154
|
}
|
|
119
155
|
```
|
|
120
156
|
|
|
@@ -130,17 +166,82 @@ type WalletAdapterResolver = (id: WalletId) => WalletAdapter | Promise<WalletAda
|
|
|
130
166
|
|
|
131
167
|
The adapter implements `WalletAdapter` from `@pollar/core`:
|
|
132
168
|
|
|
133
|
-
| `WalletAdapter` method | Kit call
|
|
134
|
-
| ---------------------------- |
|
|
135
|
-
| `isAvailable()` | `StellarWalletsKit.setWallet(id)`
|
|
136
|
-
| `connect()` | `setWallet(id)` → `fetchAddress()`
|
|
137
|
-
| `disconnect()` | `StellarWalletsKit.disconnect()`
|
|
138
|
-
| `getPublicKey()` | `StellarWalletsKit.getAddress()`
|
|
139
|
-
| `signTransaction(xdr, opts)` | `setWallet(id)` → `signTransaction(xdr, opts)`
|
|
140
|
-
| `signAuthEntry(xdr, opts)` | `setWallet(id)` → `signAuthEntry(xdr, opts)`
|
|
169
|
+
| `WalletAdapter` method | Kit call |
|
|
170
|
+
| ---------------------------- | ---------------------------------------------- |
|
|
171
|
+
| `isAvailable()` | `StellarWalletsKit.setWallet(id)` |
|
|
172
|
+
| `connect()` | `setWallet(id)` → `fetchAddress()` |
|
|
173
|
+
| `disconnect()` | `StellarWalletsKit.disconnect()` |
|
|
174
|
+
| `getPublicKey()` | `StellarWalletsKit.getAddress()` |
|
|
175
|
+
| `signTransaction(xdr, opts)` | `setWallet(id)` → `signTransaction(xdr, opts)` |
|
|
176
|
+
| `signAuthEntry(xdr, opts)` | `setWallet(id)` → `signAuthEntry(xdr, opts)` |
|
|
141
177
|
|
|
142
178
|
`setWallet` is called before every operation so a single `StellarWalletsKit.init({ modules })` covers many wallets — `PollarClient` resolves a fresh adapter instance per `WalletId`, and the kit routes to the correct module under the hood.
|
|
143
179
|
|
|
180
|
+
## Wallet picker UI (`/picker`)
|
|
181
|
+
|
|
182
|
+
The `/picker` subpath ships a React component that renders the kit's full
|
|
183
|
+
wallet list inside Pollar's `LoginModal`. It plugs into the
|
|
184
|
+
`ui.renderWallets` slot on `<PollarProvider>` (new in `@pollar/react@0.8.0`).
|
|
185
|
+
|
|
186
|
+
> **React is an optional peer dep.** Only the `/picker` subpath pulls in
|
|
187
|
+
> `react` / `react-dom` / `@pollar/react`. Headless consumers of
|
|
188
|
+
> `stellarWalletsKit({ network })` keep working with zero React in the bundle.
|
|
189
|
+
|
|
190
|
+
### Bundle helper
|
|
191
|
+
|
|
192
|
+
`createStellarWalletsKitBundle` builds both halves of the integration
|
|
193
|
+
(signing resolver + picker slot) from a single options object, so the picker
|
|
194
|
+
can only show wallets that signing actually supports:
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
import { PollarProvider } from '@pollar/react';
|
|
198
|
+
import { createStellarWalletsKitBundle } from '@pollar/stellar-wallets-kit-adapter/picker';
|
|
199
|
+
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
200
|
+
|
|
201
|
+
const bundle = createStellarWalletsKitBundle({
|
|
202
|
+
network: Networks.PUBLIC,
|
|
203
|
+
// Optional — subset, order, layout, theme, labels: see `KitPickerOptions`
|
|
204
|
+
picker: { wallets: ['xbull', 'lobstr', 'freighter'], layout: 'list' },
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
<PollarProvider
|
|
208
|
+
client={{ apiKey: 'your-api-key', walletAdapter: bundle.walletAdapter }}
|
|
209
|
+
ui={{ renderWallets: bundle.renderWallets }}
|
|
210
|
+
>
|
|
211
|
+
{/* your app */}
|
|
212
|
+
</PollarProvider>;
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Picker component directly
|
|
216
|
+
|
|
217
|
+
If you already build the `walletAdapter` yourself (e.g. composing a custom
|
|
218
|
+
resolver), use `<KitWalletPicker>` directly inside a `renderWallets` slot:
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
import { KitWalletPicker } from '@pollar/stellar-wallets-kit-adapter/picker';
|
|
222
|
+
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
223
|
+
|
|
224
|
+
<PollarProvider
|
|
225
|
+
client={{ apiKey: '…', walletAdapter: myResolver }}
|
|
226
|
+
ui={{
|
|
227
|
+
renderWallets: ({ onConnect, authState }) => (
|
|
228
|
+
<KitWalletPicker
|
|
229
|
+
onConnect={onConnect}
|
|
230
|
+
authState={authState}
|
|
231
|
+
network={Networks.PUBLIC}
|
|
232
|
+
picker={{ wallets: ['xbull', 'lobstr'], showInstalledOnly: true }}
|
|
233
|
+
/>
|
|
234
|
+
),
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
{children}
|
|
238
|
+
</PollarProvider>;
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
`<KitWalletPicker>` will lazily call `ensureInit({ network, modules })` on
|
|
242
|
+
mount, so it works whether or not `stellarWalletsKit(...)` has already been
|
|
243
|
+
called elsewhere — both share the same kit singleton.
|
|
244
|
+
|
|
144
245
|
## Direct adapter access
|
|
145
246
|
|
|
146
247
|
If you need a `WalletAdapter` instance directly (custom flows outside `PollarClient`), instantiate it yourself once the kit is initialized:
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Networks, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
|
|
2
|
+
import { WalletAdapterResolver } from '@pollar/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options that shape `<KitWalletPicker>` (from the `/picker` subpath). Kept on
|
|
6
|
+
* `StellarWalletsKitAdapterOptions` so `createStellarWalletsKitBundle()` can
|
|
7
|
+
* receive everything (network + modules + UI) in one call.
|
|
8
|
+
*/
|
|
9
|
+
interface KitPickerOptions {
|
|
10
|
+
/** Subset of wallet ids to show. Defaults to every wallet the kit reports. */
|
|
11
|
+
wallets?: string[];
|
|
12
|
+
/** Render order. Default `'as-given'` (the kit's own order). */
|
|
13
|
+
order?: 'as-given' | 'installed-first' | 'alphabetical';
|
|
14
|
+
/** Hide wallets whose `isAvailable` is false. Default `false`. */
|
|
15
|
+
showInstalledOnly?: boolean;
|
|
16
|
+
/** Per-wallet label overrides. Key = wallet id. */
|
|
17
|
+
labels?: Record<string, string>;
|
|
18
|
+
/** Visual layout. Default `'grid'`. */
|
|
19
|
+
layout?: 'grid' | 'list';
|
|
20
|
+
/** Theme passthrough — applied as CSS custom properties on the picker root. */
|
|
21
|
+
theme?: {
|
|
22
|
+
accent?: string;
|
|
23
|
+
mode?: 'light' | 'dark';
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface StellarWalletsKitAdapterOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Stellar network the kit will use for signing. Required — there is no
|
|
29
|
+
* default. The kit is a global singleton, so picking the network silently
|
|
30
|
+
* for a consumer would risk signing real-looking transactions on the wrong
|
|
31
|
+
* chain (testnet xdr signed on mainnet, etc.). Pass `Networks.TESTNET` or
|
|
32
|
+
* `Networks.PUBLIC` explicitly.
|
|
33
|
+
*/
|
|
34
|
+
network: Networks;
|
|
35
|
+
/**
|
|
36
|
+
* Wallet modules the kit should drive. Defaults to every module that works
|
|
37
|
+
* out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,
|
|
38
|
+
* HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list
|
|
39
|
+
* to add Ledger / Trezor / WalletConnect — those need extra setup (a
|
|
40
|
+
* Buffer polyfill for Ledger; constructor params for the other two) so we
|
|
41
|
+
* don't auto-include them.
|
|
42
|
+
*
|
|
43
|
+
* Import modules from their kit subpaths so the bundle stays lean:
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
modules?: ModuleInterface[];
|
|
49
|
+
/**
|
|
50
|
+
* Picker-specific options. Only consumed by `<KitWalletPicker>` /
|
|
51
|
+
* `createStellarWalletsKitBundle` (the `/picker` subpath). The resolver
|
|
52
|
+
* itself ignores them.
|
|
53
|
+
*/
|
|
54
|
+
picker?: KitPickerOptions;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass
|
|
58
|
+
* the result to `PollarClientConfig.walletAdapter` so Pollar can use any of
|
|
59
|
+
* the kit's modules without `@pollar/core` having to depend on the kit.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
64
|
+
* import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
65
|
+
*
|
|
66
|
+
* const client = new PollarClient({
|
|
67
|
+
* apiKey: '…',
|
|
68
|
+
* walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function stellarWalletsKit(options: StellarWalletsKitAdapterOptions): WalletAdapterResolver;
|
|
73
|
+
|
|
74
|
+
export { type KitPickerOptions as K, type StellarWalletsKitAdapterOptions as S, stellarWalletsKit as s };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Networks, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
|
|
2
|
+
import { WalletAdapterResolver } from '@pollar/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options that shape `<KitWalletPicker>` (from the `/picker` subpath). Kept on
|
|
6
|
+
* `StellarWalletsKitAdapterOptions` so `createStellarWalletsKitBundle()` can
|
|
7
|
+
* receive everything (network + modules + UI) in one call.
|
|
8
|
+
*/
|
|
9
|
+
interface KitPickerOptions {
|
|
10
|
+
/** Subset of wallet ids to show. Defaults to every wallet the kit reports. */
|
|
11
|
+
wallets?: string[];
|
|
12
|
+
/** Render order. Default `'as-given'` (the kit's own order). */
|
|
13
|
+
order?: 'as-given' | 'installed-first' | 'alphabetical';
|
|
14
|
+
/** Hide wallets whose `isAvailable` is false. Default `false`. */
|
|
15
|
+
showInstalledOnly?: boolean;
|
|
16
|
+
/** Per-wallet label overrides. Key = wallet id. */
|
|
17
|
+
labels?: Record<string, string>;
|
|
18
|
+
/** Visual layout. Default `'grid'`. */
|
|
19
|
+
layout?: 'grid' | 'list';
|
|
20
|
+
/** Theme passthrough — applied as CSS custom properties on the picker root. */
|
|
21
|
+
theme?: {
|
|
22
|
+
accent?: string;
|
|
23
|
+
mode?: 'light' | 'dark';
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface StellarWalletsKitAdapterOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Stellar network the kit will use for signing. Required — there is no
|
|
29
|
+
* default. The kit is a global singleton, so picking the network silently
|
|
30
|
+
* for a consumer would risk signing real-looking transactions on the wrong
|
|
31
|
+
* chain (testnet xdr signed on mainnet, etc.). Pass `Networks.TESTNET` or
|
|
32
|
+
* `Networks.PUBLIC` explicitly.
|
|
33
|
+
*/
|
|
34
|
+
network: Networks;
|
|
35
|
+
/**
|
|
36
|
+
* Wallet modules the kit should drive. Defaults to every module that works
|
|
37
|
+
* out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,
|
|
38
|
+
* HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list
|
|
39
|
+
* to add Ledger / Trezor / WalletConnect — those need extra setup (a
|
|
40
|
+
* Buffer polyfill for Ledger; constructor params for the other two) so we
|
|
41
|
+
* don't auto-include them.
|
|
42
|
+
*
|
|
43
|
+
* Import modules from their kit subpaths so the bundle stays lean:
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
modules?: ModuleInterface[];
|
|
49
|
+
/**
|
|
50
|
+
* Picker-specific options. Only consumed by `<KitWalletPicker>` /
|
|
51
|
+
* `createStellarWalletsKitBundle` (the `/picker` subpath). The resolver
|
|
52
|
+
* itself ignores them.
|
|
53
|
+
*/
|
|
54
|
+
picker?: KitPickerOptions;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass
|
|
58
|
+
* the result to `PollarClientConfig.walletAdapter` so Pollar can use any of
|
|
59
|
+
* the kit's modules without `@pollar/core` having to depend on the kit.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
64
|
+
* import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
65
|
+
*
|
|
66
|
+
* const client = new PollarClient({
|
|
67
|
+
* apiKey: '…',
|
|
68
|
+
* walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function stellarWalletsKit(options: StellarWalletsKitAdapterOptions): WalletAdapterResolver;
|
|
73
|
+
|
|
74
|
+
export { type KitPickerOptions as K, type StellarWalletsKitAdapterOptions as S, stellarWalletsKit as s };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { WalletAdapter, WalletId, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse
|
|
2
|
-
|
|
1
|
+
import { WalletAdapter, WalletId, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse } from '@pollar/core';
|
|
2
|
+
export { K as KitPickerOptions, S as StellarWalletsKitAdapterOptions, s as stellarWalletsKit } from './factory-D58ktBBa.mjs';
|
|
3
|
+
import '@creit.tech/stellar-wallets-kit';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`
|
|
@@ -19,42 +20,4 @@ declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
|
19
20
|
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Stellar network the kit will use for signing. Defaults to `Networks.TESTNET`.
|
|
25
|
-
*/
|
|
26
|
-
network?: Networks;
|
|
27
|
-
/**
|
|
28
|
-
* Wallet modules the kit should drive. Defaults to every module that works
|
|
29
|
-
* out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,
|
|
30
|
-
* HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list
|
|
31
|
-
* to add Ledger / Trezor / WalletConnect — those need extra setup (a
|
|
32
|
-
* Buffer polyfill for Ledger; constructor params for the other two) so we
|
|
33
|
-
* don't auto-include them.
|
|
34
|
-
*
|
|
35
|
-
* Import modules from their kit subpaths so the bundle stays lean:
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
modules?: ModuleInterface[];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass
|
|
44
|
-
* the result to `PollarClientConfig.walletAdapter` so Pollar can use any of
|
|
45
|
-
* the kit's modules without `@pollar/core` having to depend on the kit.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
50
|
-
* import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
51
|
-
*
|
|
52
|
-
* const client = new PollarClient({
|
|
53
|
-
* apiKey: '…',
|
|
54
|
-
* walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
declare function stellarWalletsKit(options?: StellarWalletsKitAdapterOptions): WalletAdapterResolver;
|
|
59
|
-
|
|
60
|
-
export { StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, stellarWalletsKit };
|
|
23
|
+
export { StellarWalletsKitAdapter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { WalletAdapter, WalletId, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse
|
|
2
|
-
|
|
1
|
+
import { WalletAdapter, WalletId, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse } from '@pollar/core';
|
|
2
|
+
export { K as KitPickerOptions, S as StellarWalletsKitAdapterOptions, s as stellarWalletsKit } from './factory-D58ktBBa.js';
|
|
3
|
+
import '@creit.tech/stellar-wallets-kit';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`
|
|
@@ -19,42 +20,4 @@ declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
|
19
20
|
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Stellar network the kit will use for signing. Defaults to `Networks.TESTNET`.
|
|
25
|
-
*/
|
|
26
|
-
network?: Networks;
|
|
27
|
-
/**
|
|
28
|
-
* Wallet modules the kit should drive. Defaults to every module that works
|
|
29
|
-
* out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,
|
|
30
|
-
* HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list
|
|
31
|
-
* to add Ledger / Trezor / WalletConnect — those need extra setup (a
|
|
32
|
-
* Buffer polyfill for Ledger; constructor params for the other two) so we
|
|
33
|
-
* don't auto-include them.
|
|
34
|
-
*
|
|
35
|
-
* Import modules from their kit subpaths so the bundle stays lean:
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
modules?: ModuleInterface[];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass
|
|
44
|
-
* the result to `PollarClientConfig.walletAdapter` so Pollar can use any of
|
|
45
|
-
* the kit's modules without `@pollar/core` having to depend on the kit.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
50
|
-
* import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
51
|
-
*
|
|
52
|
-
* const client = new PollarClient({
|
|
53
|
-
* apiKey: '…',
|
|
54
|
-
* walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
declare function stellarWalletsKit(options?: StellarWalletsKitAdapterOptions): WalletAdapterResolver;
|
|
59
|
-
|
|
60
|
-
export { StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, stellarWalletsKit };
|
|
23
|
+
export { StellarWalletsKitAdapter };
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,59 @@ var onekey = require('@creit.tech/stellar-wallets-kit/modules/onekey');
|
|
|
14
14
|
var rabet = require('@creit.tech/stellar-wallets-kit/modules/rabet');
|
|
15
15
|
var xbull = require('@creit.tech/stellar-wallets-kit/modules/xbull');
|
|
16
16
|
|
|
17
|
+
// src/StellarWalletsKitAdapter.ts
|
|
18
|
+
var initialised = false;
|
|
19
|
+
var initNetwork = null;
|
|
20
|
+
function buildDefaultModules() {
|
|
21
|
+
return [
|
|
22
|
+
new albedo.AlbedoModule(),
|
|
23
|
+
new bitget.BitgetModule(),
|
|
24
|
+
new cactuslink.CactusLinkModule(),
|
|
25
|
+
new fordefi.FordefiModule(),
|
|
26
|
+
new freighter.FreighterModule(),
|
|
27
|
+
new hana.HanaModule(),
|
|
28
|
+
new hotwallet.HotWalletModule(),
|
|
29
|
+
new klever.KleverModule(),
|
|
30
|
+
new lobstr.LobstrModule(),
|
|
31
|
+
new onekey.OneKeyModule(),
|
|
32
|
+
new rabet.RabetModule(),
|
|
33
|
+
new xbull.xBullModule()
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
function ensureInit(options) {
|
|
37
|
+
if (initialised) {
|
|
38
|
+
if (options.network && options.network !== initNetwork) {
|
|
39
|
+
console.warn(
|
|
40
|
+
`[StellarWalletsKit] Already initialised with network "${initNetwork}". Ignoring attempted reconfiguration to "${options.network}". The kit is a global singleton \u2014 reload the page to change networks.`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!options.network) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"[StellarWalletsKit] `network` is required \u2014 pass `Networks.TESTNET` or `Networks.PUBLIC` to `stellarWalletsKit({ network })`. The kit is a global singleton, so the network has to be chosen explicitly at init."
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
stellarWalletsKit$1.StellarWalletsKit.init({
|
|
51
|
+
network: options.network,
|
|
52
|
+
modules: options.modules ?? buildDefaultModules()
|
|
53
|
+
});
|
|
54
|
+
initNetwork = options.network;
|
|
55
|
+
initialised = true;
|
|
56
|
+
}
|
|
57
|
+
function getInitNetwork() {
|
|
58
|
+
if (initNetwork === null) {
|
|
59
|
+
throw new Error("[StellarWalletsKit] not initialised \u2014 call `stellarWalletsKit({ network })` first");
|
|
60
|
+
}
|
|
61
|
+
return initNetwork;
|
|
62
|
+
}
|
|
63
|
+
function stellarWalletsKit(options) {
|
|
64
|
+
return (id) => {
|
|
65
|
+
ensureInit(options);
|
|
66
|
+
return new StellarWalletsKitAdapter(id);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
17
70
|
// src/StellarWalletsKitAdapter.ts
|
|
18
71
|
var StellarWalletsKitAdapter = class {
|
|
19
72
|
constructor(walletId) {
|
|
@@ -22,9 +75,11 @@ var StellarWalletsKitAdapter = class {
|
|
|
22
75
|
}
|
|
23
76
|
async isAvailable() {
|
|
24
77
|
try {
|
|
25
|
-
stellarWalletsKit$1.StellarWalletsKit.
|
|
26
|
-
|
|
27
|
-
|
|
78
|
+
const supported = await stellarWalletsKit$1.StellarWalletsKit.refreshSupportedWallets();
|
|
79
|
+
const wallet = supported.find((w) => w.id === String(this.type));
|
|
80
|
+
return wallet?.isAvailable ?? false;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.warn(`[StellarWalletsKit] isAvailable probe failed for "${this.type}"`, err);
|
|
28
83
|
return false;
|
|
29
84
|
}
|
|
30
85
|
}
|
|
@@ -55,9 +110,13 @@ var StellarWalletsKitAdapter = class {
|
|
|
55
110
|
}
|
|
56
111
|
}
|
|
57
112
|
async signTransaction(xdr, options) {
|
|
113
|
+
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`[StellarWalletsKit] networkPassphrase override "${options.networkPassphrase}" does not match the network configured at init ("${getInitNetwork()}"). The kit is a global singleton \u2014 configure one network at \`stellarWalletsKit({ network })\` and use that for every call.`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
58
118
|
stellarWalletsKit$1.StellarWalletsKit.setWallet(String(this.type));
|
|
59
119
|
const result = await stellarWalletsKit$1.StellarWalletsKit.signTransaction(xdr, {
|
|
60
|
-
...options?.networkPassphrase !== void 0 && { networkPassphrase: options.networkPassphrase },
|
|
61
120
|
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
62
121
|
});
|
|
63
122
|
return { signedTxXdr: result.signedTxXdr };
|
|
@@ -70,37 +129,6 @@ var StellarWalletsKitAdapter = class {
|
|
|
70
129
|
return { signedAuthEntry: result.signedAuthEntry };
|
|
71
130
|
}
|
|
72
131
|
};
|
|
73
|
-
var initialised = false;
|
|
74
|
-
function buildDefaultModules() {
|
|
75
|
-
return [
|
|
76
|
-
new albedo.AlbedoModule(),
|
|
77
|
-
new bitget.BitgetModule(),
|
|
78
|
-
new cactuslink.CactusLinkModule(),
|
|
79
|
-
new fordefi.FordefiModule(),
|
|
80
|
-
new freighter.FreighterModule(),
|
|
81
|
-
new hana.HanaModule(),
|
|
82
|
-
new hotwallet.HotWalletModule(),
|
|
83
|
-
new klever.KleverModule(),
|
|
84
|
-
new lobstr.LobstrModule(),
|
|
85
|
-
new onekey.OneKeyModule(),
|
|
86
|
-
new rabet.RabetModule(),
|
|
87
|
-
new xbull.xBullModule()
|
|
88
|
-
];
|
|
89
|
-
}
|
|
90
|
-
function ensureInit(options) {
|
|
91
|
-
if (initialised) return;
|
|
92
|
-
stellarWalletsKit$1.StellarWalletsKit.init({
|
|
93
|
-
network: options.network ?? stellarWalletsKit$1.Networks.TESTNET,
|
|
94
|
-
modules: options.modules ?? buildDefaultModules()
|
|
95
|
-
});
|
|
96
|
-
initialised = true;
|
|
97
|
-
}
|
|
98
|
-
function stellarWalletsKit(options = {}) {
|
|
99
|
-
return (id) => {
|
|
100
|
-
ensureInit(options);
|
|
101
|
-
return new StellarWalletsKitAdapter(id);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
132
|
|
|
105
133
|
exports.StellarWalletsKitAdapter = StellarWalletsKitAdapter;
|
|
106
134
|
exports.stellarWalletsKit = stellarWalletsKit;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/StellarWalletsKitAdapter.ts","../src/factory.ts"],"names":["StellarWalletsKit","AlbedoModule","BitgetModule","CactusLinkModule","FordefiModule","FreighterModule","HanaModule","HotWalletModule","KleverModule","LobstrModule","OneKeyModule","Rabet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rB,IAAIC,qBAAA,EAAc;AAAA,IAClB,IAAIC,yBAAA,EAAgB;AAAA,IACpB,IAAIC,eAAA,EAAW;AAAA,IACf,IAAIC,yBAAA,EAAgB;AAAA,IACpB,IAAIC,mBAAA,EAAa;AAAA,IACjB,IAAIC,mBAAA,EAAa;AAAA,IACjB,IAAIC,mBAAA,EAAa;AAAA,IACjB,IAAIC,iBAAA,EAAY;AAAA,IAChB,IAAIC,iBAAA;AAAY,GAClB;AACF;AAEA,SAAS,WAAW,OAAA,EAAgD;AAClE,EAAA,IAAI,WAAA,EAAa;AACjB,EAAAZ,sCAAkB,IAAA,CAAK;AAAA,IACrB,OAAA,EAAS,OAAA,CAAQ,OAAA,IAAWa,4BAAA,CAAS,OAAA;AAAA,IACrC,OAAA,EAAS,OAAA,CAAQ,OAAA,IAAW,mBAAA;AAAoB,GACjD,CAAA;AACD,EAAA,WAAA,GAAc,IAAA;AAChB;AAkBO,SAAS,iBAAA,CAAkB,OAAA,GAA2C,EAAC,EAA0B;AACtG,EAAA,OAAO,CAAC,EAAA,KAAiB;AACvB,IAAA,UAAA,CAAW,OAAO,CAAA;AAClB,IAAA,OAAO,IAAI,yBAAyB,EAAE,CAAA;AAAA,EACxC,CAAA;AACF","file":"index.js","sourcesContent":["import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';\nimport type {\n ConnectWalletResponse,\n SignAuthEntryOptions,\n SignAuthEntryResponse,\n SignTransactionOptions,\n SignTransactionResponse,\n WalletAdapter,\n WalletId,\n} from '@pollar/core';\n\n/**\n * Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`\n * contract. The kit is a global singleton — `setWallet` is called before every\n * operation so the correct module handles the request, which lets a single\n * `StellarWalletsKit.init(...)` cover many wallet modules.\n */\nexport class StellarWalletsKitAdapter implements WalletAdapter {\n readonly type: WalletId;\n private _address: string | null = null;\n\n constructor(walletId: WalletId) {\n this.type = walletId;\n }\n\n async isAvailable(): Promise<boolean> {\n try {\n StellarWalletsKit.setWallet(String(this.type));\n // The kit doesn't expose a top-level `isAvailable`; once the module is\n // selected, attempting an address fetch is the cheapest probe — but it\n // can pop UI on some wallets. Return true and let `connect()` surface\n // the real availability error if any.\n return true;\n } catch {\n return false;\n }\n }\n\n async connect(): Promise<ConnectWalletResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const { address } = await StellarWalletsKit.fetchAddress();\n if (!address) {\n throw new Error(`[StellarWalletsKit] Empty address returned for wallet \"${this.type}\"`);\n }\n this._address = address;\n return { address, publicKey: address };\n }\n\n async disconnect(): Promise<void> {\n try {\n await StellarWalletsKit.disconnect();\n } finally {\n this._address = null;\n }\n }\n\n async getPublicKey(): Promise<string | null> {\n if (this._address) return this._address;\n try {\n const { address } = await StellarWalletsKit.getAddress();\n this._address = address ?? null;\n return this._address;\n } catch {\n return null;\n }\n }\n\n async signTransaction(xdr: string, options?: SignTransactionOptions): Promise<SignTransactionResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const result = await StellarWalletsKit.signTransaction(xdr, {\n ...(options?.networkPassphrase !== undefined && { networkPassphrase: options.networkPassphrase }),\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedTxXdr: result.signedTxXdr };\n }\n\n async signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const result = await StellarWalletsKit.signAuthEntry(entryXdr, {\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedAuthEntry: result.signedAuthEntry };\n }\n}\n","import { type ModuleInterface, Networks, StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';\nimport { AlbedoModule } from '@creit.tech/stellar-wallets-kit/modules/albedo';\nimport { BitgetModule } from '@creit.tech/stellar-wallets-kit/modules/bitget';\nimport { CactusLinkModule } from '@creit.tech/stellar-wallets-kit/modules/cactuslink';\nimport { FordefiModule } from '@creit.tech/stellar-wallets-kit/modules/fordefi';\nimport { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';\nimport { HanaModule } from '@creit.tech/stellar-wallets-kit/modules/hana';\nimport { HotWalletModule } from '@creit.tech/stellar-wallets-kit/modules/hotwallet';\nimport { KleverModule } from '@creit.tech/stellar-wallets-kit/modules/klever';\nimport { LobstrModule } from '@creit.tech/stellar-wallets-kit/modules/lobstr';\nimport { OneKeyModule } from '@creit.tech/stellar-wallets-kit/modules/onekey';\nimport { RabetModule } from '@creit.tech/stellar-wallets-kit/modules/rabet';\nimport { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';\nimport type { WalletAdapterResolver, WalletId } from '@pollar/core';\nimport { StellarWalletsKitAdapter } from './StellarWalletsKitAdapter';\n\nexport interface StellarWalletsKitAdapterOptions {\n /**\n * Stellar network the kit will use for signing. Defaults to `Networks.TESTNET`.\n */\n network?: Networks;\n /**\n * Wallet modules the kit should drive. Defaults to every module that works\n * out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,\n * HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list\n * to add Ledger / Trezor / WalletConnect — those need extra setup (a\n * Buffer polyfill for Ledger; constructor params for the other two) so we\n * don't auto-include them.\n *\n * Import modules from their kit subpaths so the bundle stays lean:\n * ```ts\n * import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';\n * ```\n */\n modules?: ModuleInterface[];\n}\n\nlet initialised = false;\n\nfunction buildDefaultModules(): ModuleInterface[] {\n return [\n new AlbedoModule(),\n new BitgetModule(),\n new CactusLinkModule(),\n new FordefiModule(),\n new FreighterModule(),\n new HanaModule(),\n new HotWalletModule(),\n new KleverModule(),\n new LobstrModule(),\n new OneKeyModule(),\n new RabetModule(),\n new xBullModule(),\n ];\n}\n\nfunction ensureInit(options: StellarWalletsKitAdapterOptions): void {\n if (initialised) return;\n StellarWalletsKit.init({\n network: options.network ?? Networks.TESTNET,\n modules: options.modules ?? buildDefaultModules(),\n });\n initialised = true;\n}\n\n/**\n * Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass\n * the result to `PollarClientConfig.walletAdapter` so Pollar can use any of\n * the kit's modules without `@pollar/core` having to depend on the kit.\n *\n * @example\n * ```ts\n * import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';\n * import { Networks } from '@creit.tech/stellar-wallets-kit';\n *\n * const client = new PollarClient({\n * apiKey: '…',\n * walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),\n * });\n * ```\n */\nexport function stellarWalletsKit(options: StellarWalletsKitAdapterOptions = {}): WalletAdapterResolver {\n return (id: WalletId) => {\n ensureInit(options);\n return new StellarWalletsKitAdapter(id);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/factory.ts","../src/StellarWalletsKitAdapter.ts"],"names":["AlbedoModule","BitgetModule","CactusLinkModule","FordefiModule","FreighterModule","HanaModule","HotWalletModule","KleverModule","LobstrModule","OneKeyModule","RabetModule","xBullModule","StellarWalletsKit"],"mappings":";;;;;;;;;;;;;;;;;AAmEA,IAAI,WAAA,GAAc,KAAA;AAClB,IAAI,WAAA,GAA+B,IAAA;AAG5B,SAAS,mBAAA,GAAyC;AACvD,EAAA,OAAO;AAAA,IACL,IAAIA,mBAAA,EAAa;AAAA,IACjB,IAAIC,mBAAA,EAAa;AAAA,IACjB,IAAIC,2BAAA,EAAiB;AAAA,IACrB,IAAIC,qBAAA,EAAc;AAAA,IAClB,IAAIC,yBAAA,EAAgB;AAAA,IACpB,IAAIC,eAAA,EAAW;AAAA,IACf,IAAIC,yBAAA,EAAgB;AAAA,IACpB,IAAIC,mBAAA,EAAa;AAAA,IACjB,IAAIC,mBAAA,EAAa;AAAA,IACjB,IAAIC,mBAAA,EAAa;AAAA,IACjB,IAAIC,iBAAA,EAAY;AAAA,IAChB,IAAIC,iBAAA;AAAY,GAClB;AACF;AAUO,SAAS,WAAW,OAAA,EAAyD;AAClF,EAAA,IAAI,WAAA,EAAa;AAIf,IAAA,IAAI,OAAA,C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T;AAAA,EACF;AAAA,EAEA,MAAM,eAAA,CAAgB,GAAA,EAAa,OAAA,EAAoE;AACrG,IAAA,IAAI,SAAS,iBAAA,KAAsB,MAAA,IAAa,OAAA,CAAQ,iBAAA,KAAsB,gBAAe,EAAG;AAC9F,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,gDAAA,EAAmD,OAAA,CAAQ,iBAAiB,CAAA,kDAAA,EAAqD,gBAAgB,CAAA,iIAAA;AAAA,OACnJ;AAAA,IACF;AACA,IAAAA,qCAAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAC7C,IAAA,MAAM,MAAA,GAAS,MAAMA,qCAAAA,CAAkB,eAAA,CAAgB,GAAA,EAAK;AAAA,MAC1D,GAAI,OAAA,EAAS,aAAA,KAAkB,UAAa,EAAE,OAAA,EAAS,QAAQ,aAAA;AAAc,KAC9E,CAAA;AACD,IAAA,OAAO,EAAE,WAAA,EAAa,MAAA,CAAO,WAAA,EAAY;AAAA,EAC3C;AAAA,EAEA,MAAM,aAAA,CAAc,QAAA,EAAkB,OAAA,EAAgE;AACpG,IAAAA,qCAAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAC7C,IAAA,MAAM,MAAA,GAAS,MAAMA,qCAAAA,CAAkB,aAAA,CAAc,QAAA,EAAU;AAAA,MAC7D,GAAI,OAAA,EAAS,aAAA,KAAkB,UAAa,EAAE,OAAA,EAAS,QAAQ,aAAA;AAAc,KAC9E,CAAA;AACD,IAAA,OAAO,EAAE,eAAA,EAAiB,MAAA,CAAO,eAAA,EAAgB;AAAA,EACnD;AACF","file":"index.js","sourcesContent":["import { type ModuleInterface, Networks, StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';\nimport { AlbedoModule } from '@creit.tech/stellar-wallets-kit/modules/albedo';\nimport { BitgetModule } from '@creit.tech/stellar-wallets-kit/modules/bitget';\nimport { CactusLinkModule } from '@creit.tech/stellar-wallets-kit/modules/cactuslink';\nimport { FordefiModule } from '@creit.tech/stellar-wallets-kit/modules/fordefi';\nimport { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';\nimport { HanaModule } from '@creit.tech/stellar-wallets-kit/modules/hana';\nimport { HotWalletModule } from '@creit.tech/stellar-wallets-kit/modules/hotwallet';\nimport { KleverModule } from '@creit.tech/stellar-wallets-kit/modules/klever';\nimport { LobstrModule } from '@creit.tech/stellar-wallets-kit/modules/lobstr';\nimport { OneKeyModule } from '@creit.tech/stellar-wallets-kit/modules/onekey';\nimport { RabetModule } from '@creit.tech/stellar-wallets-kit/modules/rabet';\nimport { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';\nimport type { WalletAdapterResolver, WalletId } from '@pollar/core';\nimport { StellarWalletsKitAdapter } from './StellarWalletsKitAdapter';\n\n/**\n * Options that shape `<KitWalletPicker>` (from the `/picker` subpath). Kept on\n * `StellarWalletsKitAdapterOptions` so `createStellarWalletsKitBundle()` can\n * receive everything (network + modules + UI) in one call.\n */\nexport interface KitPickerOptions {\n /** Subset of wallet ids to show. Defaults to every wallet the kit reports. */\n wallets?: string[];\n /** Render order. Default `'as-given'` (the kit's own order). */\n order?: 'as-given' | 'installed-first' | 'alphabetical';\n /** Hide wallets whose `isAvailable` is false. Default `false`. */\n showInstalledOnly?: boolean;\n /** Per-wallet label overrides. Key = wallet id. */\n labels?: Record<string, string>;\n /** Visual layout. Default `'grid'`. */\n layout?: 'grid' | 'list';\n /** Theme passthrough — applied as CSS custom properties on the picker root. */\n theme?: { accent?: string; mode?: 'light' | 'dark' };\n}\n\nexport interface StellarWalletsKitAdapterOptions {\n /**\n * Stellar network the kit will use for signing. Required — there is no\n * default. The kit is a global singleton, so picking the network silently\n * for a consumer would risk signing real-looking transactions on the wrong\n * chain (testnet xdr signed on mainnet, etc.). Pass `Networks.TESTNET` or\n * `Networks.PUBLIC` explicitly.\n */\n network: Networks;\n /**\n * Wallet modules the kit should drive. Defaults to every module that works\n * out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,\n * HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list\n * to add Ledger / Trezor / WalletConnect — those need extra setup (a\n * Buffer polyfill for Ledger; constructor params for the other two) so we\n * don't auto-include them.\n *\n * Import modules from their kit subpaths so the bundle stays lean:\n * ```ts\n * import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';\n * ```\n */\n modules?: ModuleInterface[];\n /**\n * Picker-specific options. Only consumed by `<KitWalletPicker>` /\n * `createStellarWalletsKitBundle` (the `/picker` subpath). The resolver\n * itself ignores them.\n */\n picker?: KitPickerOptions;\n}\n\nlet initialised = false;\nlet initNetwork: Networks | null = null;\n\n/** @internal — used by the `/picker` subpath. */\nexport function buildDefaultModules(): ModuleInterface[] {\n return [\n new AlbedoModule(),\n new BitgetModule(),\n new CactusLinkModule(),\n new FordefiModule(),\n new FreighterModule(),\n new HanaModule(),\n new HotWalletModule(),\n new KleverModule(),\n new LobstrModule(),\n new OneKeyModule(),\n new RabetModule(),\n new xBullModule(),\n ];\n}\n\n/**\n * @internal — used by the `/picker` subpath.\n *\n * Accepts `Partial<...>` because the picker may be mounted in a flow where\n * `stellarWalletsKit({ network })` has already initialised the kit elsewhere;\n * in that case the call no-ops and the missing `network` is fine. On the\n * first-time init path `network` is required and we throw if it's absent.\n */\nexport function ensureInit(options: Partial<StellarWalletsKitAdapterOptions>): void {\n if (initialised) {\n // The kit is a global singleton — a second call with a different network\n // would be silently ignored. Warn so the developer notices the\n // misconfiguration instead of debugging wrong-chain signatures later.\n if (options.network && options.network !== initNetwork) {\n console.warn(\n `[StellarWalletsKit] Already initialised with network \"${initNetwork}\". Ignoring attempted reconfiguration to \"${options.network}\". The kit is a global singleton — reload the page to change networks.`,\n );\n }\n return;\n }\n if (!options.network) {\n throw new Error(\n '[StellarWalletsKit] `network` is required — pass `Networks.TESTNET` or `Networks.PUBLIC` to `stellarWalletsKit({ network })`. The kit is a global singleton, so the network has to be chosen explicitly at init.',\n );\n }\n StellarWalletsKit.init({\n network: options.network,\n modules: options.modules ?? buildDefaultModules(),\n });\n initNetwork = options.network;\n initialised = true;\n}\n\n/** @internal — used by `StellarWalletsKitAdapter` to reject per-call network overrides that don't match init. */\nexport function getInitNetwork(): Networks {\n if (initNetwork === null) {\n throw new Error('[StellarWalletsKit] not initialised — call `stellarWalletsKit({ network })` first');\n }\n return initNetwork;\n}\n\n/**\n * Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass\n * the result to `PollarClientConfig.walletAdapter` so Pollar can use any of\n * the kit's modules without `@pollar/core` having to depend on the kit.\n *\n * @example\n * ```ts\n * import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';\n * import { Networks } from '@creit.tech/stellar-wallets-kit';\n *\n * const client = new PollarClient({\n * apiKey: '…',\n * walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),\n * });\n * ```\n */\nexport function stellarWalletsKit(options: StellarWalletsKitAdapterOptions): WalletAdapterResolver {\n return (id: WalletId) => {\n ensureInit(options);\n return new StellarWalletsKitAdapter(id);\n };\n}\n","import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';\nimport type {\n ConnectWalletResponse,\n SignAuthEntryOptions,\n SignAuthEntryResponse,\n SignTransactionOptions,\n SignTransactionResponse,\n WalletAdapter,\n WalletId,\n} from '@pollar/core';\nimport { getInitNetwork } from './factory';\n\n/**\n * Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`\n * contract. The kit is a global singleton — `setWallet` is called before every\n * operation so the correct module handles the request, which lets a single\n * `StellarWalletsKit.init(...)` cover many wallet modules.\n */\nexport class StellarWalletsKitAdapter implements WalletAdapter {\n readonly type: WalletId;\n private _address: string | null = null;\n\n constructor(walletId: WalletId) {\n this.type = walletId;\n }\n\n async isAvailable(): Promise<boolean> {\n // `refreshSupportedWallets()` probes every module's own `isAvailable()`\n // hook (modules promise <1000ms per the kit contract) and returns a\n // static snapshot. This avoids the old false-positive where we always\n // claimed availability and let `connect()` fail later — the picker / UI\n // can now short-circuit on `wallet_not_installed` immediately.\n try {\n const supported = await StellarWalletsKit.refreshSupportedWallets();\n const wallet = supported.find((w) => w.id === String(this.type));\n return wallet?.isAvailable ?? false;\n } catch (err) {\n console.warn(`[StellarWalletsKit] isAvailable probe failed for \"${this.type}\"`, err);\n return false;\n }\n }\n\n async connect(): Promise<ConnectWalletResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const { address } = await StellarWalletsKit.fetchAddress();\n if (!address) {\n throw new Error(`[StellarWalletsKit] Empty address returned for wallet \"${this.type}\"`);\n }\n this._address = address;\n return { address, publicKey: address };\n }\n\n async disconnect(): Promise<void> {\n try {\n await StellarWalletsKit.disconnect();\n } finally {\n this._address = null;\n }\n }\n\n async getPublicKey(): Promise<string | null> {\n if (this._address) return this._address;\n try {\n const { address } = await StellarWalletsKit.getAddress();\n this._address = address ?? null;\n return this._address;\n } catch {\n return null;\n }\n }\n\n async signTransaction(xdr: string, options?: SignTransactionOptions): Promise<SignTransactionResponse> {\n if (options?.networkPassphrase !== undefined && options.networkPassphrase !== getInitNetwork()) {\n throw new Error(\n `[StellarWalletsKit] networkPassphrase override \"${options.networkPassphrase}\" does not match the network configured at init (\"${getInitNetwork()}\"). The kit is a global singleton — configure one network at \\`stellarWalletsKit({ network })\\` and use that for every call.`,\n );\n }\n StellarWalletsKit.setWallet(String(this.type));\n const result = await StellarWalletsKit.signTransaction(xdr, {\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedTxXdr: result.signedTxXdr };\n }\n\n async signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const result = await StellarWalletsKit.signAuthEntry(entryXdr, {\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedAuthEntry: result.signedAuthEntry };\n }\n}\n"]}
|