@pollar/stellar-wallets-kit-adapter 0.9.0-rc.0 → 0.10.0-rc.10
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 +20 -54
- package/dist/index.d.mts +93 -5
- package/dist/index.d.ts +93 -5
- package/dist/index.js +42 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -36
- package/dist/factory-D58ktBBa.d.mts +0 -74
- package/dist/factory-D58ktBBa.d.ts +0 -74
- package/dist/picker.d.mts +0 -45
- package/dist/picker.d.ts +0 -45
- package/dist/picker.js +0 -265
- package/dist/picker.js.map +0 -1
- package/dist/picker.mjs +0 -262
- package/dist/picker.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -52,6 +52,11 @@ Rabet, …) inside `LoginModal`, also pass the picker — see
|
|
|
52
52
|
|
|
53
53
|
The kit is a global singleton. `stellarWalletsKit(...)` returns a resolver and `StellarWalletsKit.init(...)` is called once on the first `loginWallet` call.
|
|
54
54
|
|
|
55
|
+
> **0.9.0** — `connect()` resolves to `{ address }` only (the duplicate
|
|
56
|
+
> `publicKey` field is gone, matching the new `ConnectWalletResponse`). Requires
|
|
57
|
+
> `@pollar/core@^0.9.0` / `@pollar/react@^0.9.0`. Adds `logLevel` / `logger`
|
|
58
|
+
> options (set once at init — the kit is a global singleton).
|
|
59
|
+
>
|
|
55
60
|
> **0.8.0** — `network` is **required**. The previous `Networks.TESTNET`
|
|
56
61
|
> default was removed because the kit is a global singleton, and silently
|
|
57
62
|
> picking testnet for the consumer risked signing real-looking transactions
|
|
@@ -177,71 +182,32 @@ The adapter implements `WalletAdapter` from `@pollar/core`:
|
|
|
177
182
|
|
|
178
183
|
`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.
|
|
179
184
|
|
|
180
|
-
##
|
|
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.
|
|
185
|
+
## Login UI
|
|
189
186
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
The wallets you register via `stellarWalletsKitAdapters({ network })` render
|
|
188
|
+
automatically inside Pollar's `LoginModal` — one button per wallet, collapsed
|
|
189
|
+
behind a single "Wallet" gateway button (their shared `meta.group`). Pass
|
|
190
|
+
`picker.groupLabel` to give them a distinct gateway, or `picker.labels` to
|
|
191
|
+
override individual button labels.
|
|
195
192
|
|
|
196
193
|
```tsx
|
|
197
194
|
import { PollarProvider } from '@pollar/react';
|
|
198
|
-
import {
|
|
195
|
+
import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
199
196
|
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
200
197
|
|
|
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
198
|
<PollarProvider
|
|
208
|
-
client={{
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
),
|
|
199
|
+
client={{
|
|
200
|
+
apiKey: 'your-api-key',
|
|
201
|
+
walletAdapters: stellarWalletsKitAdapters({
|
|
202
|
+
network: Networks.PUBLIC,
|
|
203
|
+
picker: { wallets: ['xbull', 'lobstr', 'freighter'] },
|
|
204
|
+
}),
|
|
235
205
|
}}
|
|
236
206
|
>
|
|
237
|
-
{
|
|
207
|
+
{/* your app */}
|
|
238
208
|
</PollarProvider>;
|
|
239
209
|
```
|
|
240
210
|
|
|
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
|
-
|
|
245
211
|
## Direct adapter access
|
|
246
212
|
|
|
247
213
|
If you need a `WalletAdapter` instance directly (custom flows outside `PollarClient`), instantiate it yourself once the kit is initialized:
|
|
@@ -254,7 +220,7 @@ import { StellarWalletsKitAdapter } from '@pollar/stellar-wallets-kit-adapter';
|
|
|
254
220
|
StellarWalletsKit.init({ network: Networks.PUBLIC, modules: [new FreighterModule()] });
|
|
255
221
|
|
|
256
222
|
const adapter = new StellarWalletsKitAdapter('freighter');
|
|
257
|
-
const {
|
|
223
|
+
const { address } = await adapter.connect();
|
|
258
224
|
```
|
|
259
225
|
|
|
260
226
|
## Writing a custom resolver
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { WalletAdapter, WalletId, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse } from '@pollar/core';
|
|
2
|
-
|
|
3
|
-
import '@creit.tech/stellar-wallets-kit';
|
|
1
|
+
import { WalletAdapter, WalletId, WalletAdapterMeta, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse, LogLevel, PollarLogger } from '@pollar/core';
|
|
2
|
+
import { Networks, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`
|
|
@@ -10,8 +9,10 @@ import '@creit.tech/stellar-wallets-kit';
|
|
|
10
9
|
*/
|
|
11
10
|
declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
12
11
|
readonly type: WalletId;
|
|
12
|
+
readonly meta: WalletAdapterMeta;
|
|
13
|
+
readonly custody: "external";
|
|
13
14
|
private _address;
|
|
14
|
-
constructor(walletId: WalletId);
|
|
15
|
+
constructor(walletId: WalletId, meta: WalletAdapterMeta);
|
|
15
16
|
isAvailable(): Promise<boolean>;
|
|
16
17
|
connect(): Promise<ConnectWalletResponse>;
|
|
17
18
|
disconnect(): Promise<void>;
|
|
@@ -20,4 +21,91 @@ declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
|
20
21
|
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Options that shape `<KitWalletPicker>` (from the `/picker` subpath). Kept on
|
|
26
|
+
* `StellarWalletsKitAdapterOptions` so `createStellarWalletsKitBundle()` can
|
|
27
|
+
* receive everything (network + modules + UI) in one call.
|
|
28
|
+
*/
|
|
29
|
+
interface KitPickerOptions {
|
|
30
|
+
/** Subset of wallet ids to show. Defaults to every wallet the kit reports. */
|
|
31
|
+
wallets?: string[];
|
|
32
|
+
/** Render order. Default `'as-given'` (the kit's own order). */
|
|
33
|
+
order?: 'as-given' | 'installed-first' | 'alphabetical';
|
|
34
|
+
/** Hide wallets whose `isAvailable` is false. Default `false`. */
|
|
35
|
+
showInstalledOnly?: boolean;
|
|
36
|
+
/** Per-wallet label overrides. Key = wallet id. */
|
|
37
|
+
labels?: Record<string, string>;
|
|
38
|
+
/**
|
|
39
|
+
* Label of the gateway button these kit wallets collapse behind in the login
|
|
40
|
+
* UI (the `meta.group` applied to every adapter this factory builds). Default
|
|
41
|
+
* `'Wallet'` — the same group as the built-in Freighter/Albedo, so they share
|
|
42
|
+
* one gateway. Set a distinct value (e.g. `'More wallets'`) to render the kit
|
|
43
|
+
* wallets as a *separate* gateway button from the built-in ones.
|
|
44
|
+
*/
|
|
45
|
+
groupLabel?: string;
|
|
46
|
+
/** Visual layout. Default `'grid'`. */
|
|
47
|
+
layout?: 'grid' | 'list';
|
|
48
|
+
/** Theme passthrough — applied as CSS custom properties on the picker root. */
|
|
49
|
+
theme?: {
|
|
50
|
+
accent?: string;
|
|
51
|
+
mode?: 'light' | 'dark';
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
interface StellarWalletsKitAdapterOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Stellar network the kit will use for signing. Required — there is no
|
|
57
|
+
* default. The kit is a global singleton, so picking the network silently
|
|
58
|
+
* for a consumer would risk signing real-looking transactions on the wrong
|
|
59
|
+
* chain (testnet xdr signed on mainnet, etc.). Pass `Networks.TESTNET` or
|
|
60
|
+
* `Networks.PUBLIC` explicitly.
|
|
61
|
+
*/
|
|
62
|
+
network: Networks;
|
|
63
|
+
/**
|
|
64
|
+
* Wallet modules the kit should drive. Defaults to every module that works
|
|
65
|
+
* out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,
|
|
66
|
+
* HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list
|
|
67
|
+
* to add Ledger / Trezor / WalletConnect — those need extra setup (a
|
|
68
|
+
* Buffer polyfill for Ledger; constructor params for the other two) so we
|
|
69
|
+
* don't auto-include them.
|
|
70
|
+
*
|
|
71
|
+
* Import modules from their kit subpaths so the bundle stays lean:
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
modules?: ModuleInterface[];
|
|
77
|
+
/**
|
|
78
|
+
* Picker-specific options. Only consumed by `<KitWalletPicker>` /
|
|
79
|
+
* `createStellarWalletsKitBundle` (the `/picker` subpath). The resolver
|
|
80
|
+
* itself ignores them.
|
|
81
|
+
*/
|
|
82
|
+
picker?: KitPickerOptions;
|
|
83
|
+
/**
|
|
84
|
+
* Minimum log severity. `silent` disables logging; otherwise `error` < `warn`
|
|
85
|
+
* < `info` < `debug`. Defaults to `'info'`. Since the kit is a global
|
|
86
|
+
* singleton, this is set once at init.
|
|
87
|
+
*/
|
|
88
|
+
logLevel?: LogLevel;
|
|
89
|
+
/** Sink for logs. Defaults to the global `console`. */
|
|
90
|
+
logger?: PollarLogger;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Build the list of {@link WalletAdapter}s backed by Stellar Wallets Kit — one
|
|
94
|
+
* per kit module — to pass to `PollarClientConfig.walletAdapters`. Each adapter
|
|
95
|
+
* carries the module's name/icon as its button `meta`. `picker.wallets` (subset)
|
|
96
|
+
* and `picker.labels` (overrides) are honored if provided.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
101
|
+
* import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
102
|
+
*
|
|
103
|
+
* const client = new PollarClient({
|
|
104
|
+
* apiKey: '…',
|
|
105
|
+
* walletAdapters: stellarWalletsKitAdapters({ network: Networks.PUBLIC }),
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function stellarWalletsKitAdapters(options: StellarWalletsKitAdapterOptions): WalletAdapter[];
|
|
110
|
+
|
|
111
|
+
export { type KitPickerOptions, StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, stellarWalletsKitAdapters };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { WalletAdapter, WalletId, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse } from '@pollar/core';
|
|
2
|
-
|
|
3
|
-
import '@creit.tech/stellar-wallets-kit';
|
|
1
|
+
import { WalletAdapter, WalletId, WalletAdapterMeta, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse, LogLevel, PollarLogger } from '@pollar/core';
|
|
2
|
+
import { Networks, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`
|
|
@@ -10,8 +9,10 @@ import '@creit.tech/stellar-wallets-kit';
|
|
|
10
9
|
*/
|
|
11
10
|
declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
12
11
|
readonly type: WalletId;
|
|
12
|
+
readonly meta: WalletAdapterMeta;
|
|
13
|
+
readonly custody: "external";
|
|
13
14
|
private _address;
|
|
14
|
-
constructor(walletId: WalletId);
|
|
15
|
+
constructor(walletId: WalletId, meta: WalletAdapterMeta);
|
|
15
16
|
isAvailable(): Promise<boolean>;
|
|
16
17
|
connect(): Promise<ConnectWalletResponse>;
|
|
17
18
|
disconnect(): Promise<void>;
|
|
@@ -20,4 +21,91 @@ declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
|
20
21
|
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Options that shape `<KitWalletPicker>` (from the `/picker` subpath). Kept on
|
|
26
|
+
* `StellarWalletsKitAdapterOptions` so `createStellarWalletsKitBundle()` can
|
|
27
|
+
* receive everything (network + modules + UI) in one call.
|
|
28
|
+
*/
|
|
29
|
+
interface KitPickerOptions {
|
|
30
|
+
/** Subset of wallet ids to show. Defaults to every wallet the kit reports. */
|
|
31
|
+
wallets?: string[];
|
|
32
|
+
/** Render order. Default `'as-given'` (the kit's own order). */
|
|
33
|
+
order?: 'as-given' | 'installed-first' | 'alphabetical';
|
|
34
|
+
/** Hide wallets whose `isAvailable` is false. Default `false`. */
|
|
35
|
+
showInstalledOnly?: boolean;
|
|
36
|
+
/** Per-wallet label overrides. Key = wallet id. */
|
|
37
|
+
labels?: Record<string, string>;
|
|
38
|
+
/**
|
|
39
|
+
* Label of the gateway button these kit wallets collapse behind in the login
|
|
40
|
+
* UI (the `meta.group` applied to every adapter this factory builds). Default
|
|
41
|
+
* `'Wallet'` — the same group as the built-in Freighter/Albedo, so they share
|
|
42
|
+
* one gateway. Set a distinct value (e.g. `'More wallets'`) to render the kit
|
|
43
|
+
* wallets as a *separate* gateway button from the built-in ones.
|
|
44
|
+
*/
|
|
45
|
+
groupLabel?: string;
|
|
46
|
+
/** Visual layout. Default `'grid'`. */
|
|
47
|
+
layout?: 'grid' | 'list';
|
|
48
|
+
/** Theme passthrough — applied as CSS custom properties on the picker root. */
|
|
49
|
+
theme?: {
|
|
50
|
+
accent?: string;
|
|
51
|
+
mode?: 'light' | 'dark';
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
interface StellarWalletsKitAdapterOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Stellar network the kit will use for signing. Required — there is no
|
|
57
|
+
* default. The kit is a global singleton, so picking the network silently
|
|
58
|
+
* for a consumer would risk signing real-looking transactions on the wrong
|
|
59
|
+
* chain (testnet xdr signed on mainnet, etc.). Pass `Networks.TESTNET` or
|
|
60
|
+
* `Networks.PUBLIC` explicitly.
|
|
61
|
+
*/
|
|
62
|
+
network: Networks;
|
|
63
|
+
/**
|
|
64
|
+
* Wallet modules the kit should drive. Defaults to every module that works
|
|
65
|
+
* out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,
|
|
66
|
+
* HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list
|
|
67
|
+
* to add Ledger / Trezor / WalletConnect — those need extra setup (a
|
|
68
|
+
* Buffer polyfill for Ledger; constructor params for the other two) so we
|
|
69
|
+
* don't auto-include them.
|
|
70
|
+
*
|
|
71
|
+
* Import modules from their kit subpaths so the bundle stays lean:
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
modules?: ModuleInterface[];
|
|
77
|
+
/**
|
|
78
|
+
* Picker-specific options. Only consumed by `<KitWalletPicker>` /
|
|
79
|
+
* `createStellarWalletsKitBundle` (the `/picker` subpath). The resolver
|
|
80
|
+
* itself ignores them.
|
|
81
|
+
*/
|
|
82
|
+
picker?: KitPickerOptions;
|
|
83
|
+
/**
|
|
84
|
+
* Minimum log severity. `silent` disables logging; otherwise `error` < `warn`
|
|
85
|
+
* < `info` < `debug`. Defaults to `'info'`. Since the kit is a global
|
|
86
|
+
* singleton, this is set once at init.
|
|
87
|
+
*/
|
|
88
|
+
logLevel?: LogLevel;
|
|
89
|
+
/** Sink for logs. Defaults to the global `console`. */
|
|
90
|
+
logger?: PollarLogger;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Build the list of {@link WalletAdapter}s backed by Stellar Wallets Kit — one
|
|
94
|
+
* per kit module — to pass to `PollarClientConfig.walletAdapters`. Each adapter
|
|
95
|
+
* carries the module's name/icon as its button `meta`. `picker.wallets` (subset)
|
|
96
|
+
* and `picker.labels` (overrides) are honored if provided.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
101
|
+
* import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
102
|
+
*
|
|
103
|
+
* const client = new PollarClient({
|
|
104
|
+
* apiKey: '…',
|
|
105
|
+
* walletAdapters: stellarWalletsKitAdapters({ network: Networks.PUBLIC }),
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function stellarWalletsKitAdapters(options: StellarWalletsKitAdapterOptions): WalletAdapter[];
|
|
110
|
+
|
|
111
|
+
export { type KitPickerOptions, StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, stellarWalletsKitAdapters };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var stellarWalletsKit
|
|
3
|
+
var stellarWalletsKit = require('@creit.tech/stellar-wallets-kit');
|
|
4
4
|
var albedo = require('@creit.tech/stellar-wallets-kit/modules/albedo');
|
|
5
5
|
var bitget = require('@creit.tech/stellar-wallets-kit/modules/bitget');
|
|
6
6
|
var cactuslink = require('@creit.tech/stellar-wallets-kit/modules/cactuslink');
|
|
@@ -13,10 +13,15 @@ var lobstr = require('@creit.tech/stellar-wallets-kit/modules/lobstr');
|
|
|
13
13
|
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
|
+
var core = require('@pollar/core');
|
|
16
17
|
|
|
17
18
|
// src/StellarWalletsKitAdapter.ts
|
|
18
19
|
var initialised = false;
|
|
19
20
|
var initNetwork = null;
|
|
21
|
+
var _log = console;
|
|
22
|
+
function getKitLogger() {
|
|
23
|
+
return _log;
|
|
24
|
+
}
|
|
20
25
|
function buildDefaultModules() {
|
|
21
26
|
return [
|
|
22
27
|
new albedo.AlbedoModule(),
|
|
@@ -34,9 +39,12 @@ function buildDefaultModules() {
|
|
|
34
39
|
];
|
|
35
40
|
}
|
|
36
41
|
function ensureInit(options) {
|
|
42
|
+
if (options.logLevel !== void 0 || options.logger !== void 0) {
|
|
43
|
+
_log = core.createLogger(options.logLevel ?? "info", options.logger);
|
|
44
|
+
}
|
|
37
45
|
if (initialised) {
|
|
38
46
|
if (options.network && options.network !== initNetwork) {
|
|
39
|
-
|
|
47
|
+
_log.warn(
|
|
40
48
|
`[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
49
|
);
|
|
42
50
|
}
|
|
@@ -47,7 +55,7 @@ function ensureInit(options) {
|
|
|
47
55
|
"[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
56
|
);
|
|
49
57
|
}
|
|
50
|
-
stellarWalletsKit
|
|
58
|
+
stellarWalletsKit.StellarWalletsKit.init({
|
|
51
59
|
network: options.network,
|
|
52
60
|
modules: options.modules ?? buildDefaultModules()
|
|
53
61
|
});
|
|
@@ -60,32 +68,41 @@ function getInitNetwork() {
|
|
|
60
68
|
}
|
|
61
69
|
return initNetwork;
|
|
62
70
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
function stellarWalletsKitAdapters(options) {
|
|
72
|
+
if (typeof window === "undefined") return [];
|
|
73
|
+
ensureInit(options);
|
|
74
|
+
const modules = options.modules ?? buildDefaultModules();
|
|
75
|
+
const wanted = options.picker?.wallets;
|
|
76
|
+
return modules.filter((m) => !wanted || wanted.includes(m.productId)).map(
|
|
77
|
+
(m) => new StellarWalletsKitAdapter(m.productId, {
|
|
78
|
+
label: options.picker?.labels?.[m.productId] ?? m.productName,
|
|
79
|
+
iconUrl: m.productIcon,
|
|
80
|
+
group: options.picker?.groupLabel ?? "Wallet"
|
|
81
|
+
})
|
|
82
|
+
);
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
// src/StellarWalletsKitAdapter.ts
|
|
71
86
|
var StellarWalletsKitAdapter = class {
|
|
72
|
-
constructor(walletId) {
|
|
87
|
+
constructor(walletId, meta) {
|
|
88
|
+
this.custody = "external";
|
|
73
89
|
this._address = null;
|
|
74
90
|
this.type = walletId;
|
|
91
|
+
this.meta = meta;
|
|
75
92
|
}
|
|
76
93
|
async isAvailable() {
|
|
77
94
|
try {
|
|
78
|
-
const supported = await stellarWalletsKit
|
|
95
|
+
const supported = await stellarWalletsKit.StellarWalletsKit.refreshSupportedWallets();
|
|
79
96
|
const wallet = supported.find((w) => w.id === String(this.type));
|
|
80
97
|
return wallet?.isAvailable ?? false;
|
|
81
98
|
} catch (err) {
|
|
82
|
-
|
|
99
|
+
getKitLogger().warn(`[StellarWalletsKit] isAvailable probe failed for "${this.type}"`, err);
|
|
83
100
|
return false;
|
|
84
101
|
}
|
|
85
102
|
}
|
|
86
103
|
async connect() {
|
|
87
|
-
stellarWalletsKit
|
|
88
|
-
const { address } = await stellarWalletsKit
|
|
104
|
+
stellarWalletsKit.StellarWalletsKit.setWallet(String(this.type));
|
|
105
|
+
const { address } = await stellarWalletsKit.StellarWalletsKit.fetchAddress();
|
|
89
106
|
if (!address) {
|
|
90
107
|
throw new Error(`[StellarWalletsKit] Empty address returned for wallet "${this.type}"`);
|
|
91
108
|
}
|
|
@@ -94,7 +111,7 @@ var StellarWalletsKitAdapter = class {
|
|
|
94
111
|
}
|
|
95
112
|
async disconnect() {
|
|
96
113
|
try {
|
|
97
|
-
await stellarWalletsKit
|
|
114
|
+
await stellarWalletsKit.StellarWalletsKit.disconnect();
|
|
98
115
|
} finally {
|
|
99
116
|
this._address = null;
|
|
100
117
|
}
|
|
@@ -102,7 +119,7 @@ var StellarWalletsKitAdapter = class {
|
|
|
102
119
|
async getPublicKey() {
|
|
103
120
|
if (this._address) return this._address;
|
|
104
121
|
try {
|
|
105
|
-
const { address } = await stellarWalletsKit
|
|
122
|
+
const { address } = await stellarWalletsKit.StellarWalletsKit.getAddress();
|
|
106
123
|
this._address = address ?? null;
|
|
107
124
|
return this._address;
|
|
108
125
|
} catch {
|
|
@@ -115,15 +132,20 @@ var StellarWalletsKitAdapter = class {
|
|
|
115
132
|
`[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
133
|
);
|
|
117
134
|
}
|
|
118
|
-
stellarWalletsKit
|
|
119
|
-
const result = await stellarWalletsKit
|
|
135
|
+
stellarWalletsKit.StellarWalletsKit.setWallet(String(this.type));
|
|
136
|
+
const result = await stellarWalletsKit.StellarWalletsKit.signTransaction(xdr, {
|
|
120
137
|
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
121
138
|
});
|
|
122
139
|
return { signedTxXdr: result.signedTxXdr };
|
|
123
140
|
}
|
|
124
141
|
async signAuthEntry(entryXdr, options) {
|
|
125
|
-
|
|
126
|
-
|
|
142
|
+
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`[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.`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
stellarWalletsKit.StellarWalletsKit.setWallet(String(this.type));
|
|
148
|
+
const result = await stellarWalletsKit.StellarWalletsKit.signAuthEntry(entryXdr, {
|
|
127
149
|
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
128
150
|
});
|
|
129
151
|
return { signedAuthEntry: result.signedAuthEntry };
|
|
@@ -131,6 +153,6 @@ var StellarWalletsKitAdapter = class {
|
|
|
131
153
|
};
|
|
132
154
|
|
|
133
155
|
exports.StellarWalletsKitAdapter = StellarWalletsKitAdapter;
|
|
134
|
-
exports.
|
|
156
|
+
exports.stellarWalletsKitAdapters = stellarWalletsKitAdapters;
|
|
135
157
|
//# sourceMappingURL=index.js.map
|
|
136
158
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CAAQ,OAAA,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,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 };\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/factory.ts","../src/StellarWalletsKitAdapter.ts"],"names":["AlbedoModule","BitgetModule","CactusLinkModule","FordefiModule","FreighterModule","HanaModule","HotWalletModule","KleverModule","LobstrModule","OneKeyModule","RabetModule","xBullModule","createLogger","StellarWalletsKit"],"mappings":";;;;;;;;;;;;;;;;;;AAmFA,IAAI,WAAA,GAAc,KAAA;AAClB,IAAI,WAAA,GAA+B,IAAA;AACnC,IAAI,IAAA,GAAqB,OAAA;AAGlB,SAAS,YAAA,GAA6B;AAC3C,EAAA,OAAO,IAAA;AACT;AAGO,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,OAAA,CAAQ,QAAA,KAAa,MAAA,IAAa,OAAA,CAAQ,WAAW,MAAA,EAAW;AAClE,IAAA,IAAA,GAAOC,iBAAA,CAAa,OAAA,CAAQ,QAAA,IAAY,MAAA,EAAQ,QAAQ,MAAM,CAAA;AAAA,EAChE;AACA,EAAA,IAAI,WAAA,EAAa;AAIf,IAAA,IAAI,OAAA,CAAQ,OAAA,IAAW,OAAA,CAAQ,OAAA,KAAY,WAAA,EAAa;AACtD,MAAA,IAAA,CAAK,IAAA;AAAA,QACH,CAAA,sDAAA,EAAyD,WAAW,CAAA,0CAAA,EAA6C,OAAA,CAAQ,OAAO,CAAA,2EAAA;AAAA,OAClI;AAAA,I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AA,gDAAA,EAAmD,OAAA,CAAQ,iBAAiB,CAAA,kDAAA,EAAqD,gBAAgB,CAAA,iIAAA;AAAA,OACnJ;AAAA,IACF;AACA,IAAAA,mCAAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAC7C,IAAA,MAAM,MAAA,GAAS,MAAMA,mCAAAA,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 { createLogger, type LogLevel, type PollarLogger, type WalletAdapter } 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 /**\n * Label of the gateway button these kit wallets collapse behind in the login\n * UI (the `meta.group` applied to every adapter this factory builds). Default\n * `'Wallet'` — the same group as the built-in Freighter/Albedo, so they share\n * one gateway. Set a distinct value (e.g. `'More wallets'`) to render the kit\n * wallets as a *separate* gateway button from the built-in ones.\n */\n groupLabel?: 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 * Minimum log severity. `silent` disables logging; otherwise `error` < `warn`\n * < `info` < `debug`. Defaults to `'info'`. Since the kit is a global\n * singleton, this is set once at init.\n */\n logLevel?: LogLevel;\n /** Sink for logs. Defaults to the global `console`. */\n logger?: PollarLogger;\n}\n\nlet initialised = false;\nlet initNetwork: Networks | null = null;\nlet _log: PollarLogger = console;\n\n/** The kit's configured logger (set at init). Used by the adapter + picker. */\nexport function getKitLogger(): PollarLogger {\n return _log;\n}\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 (options.logLevel !== undefined || options.logger !== undefined) {\n _log = createLogger(options.logLevel ?? 'info', options.logger);\n }\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 _log.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 the list of {@link WalletAdapter}s backed by Stellar Wallets Kit — one\n * per kit module — to pass to `PollarClientConfig.walletAdapters`. Each adapter\n * carries the module's name/icon as its button `meta`. `picker.wallets` (subset)\n * and `picker.labels` (overrides) are honored if provided.\n *\n * @example\n * ```ts\n * import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';\n * import { Networks } from '@creit.tech/stellar-wallets-kit';\n *\n * const client = new PollarClient({\n * apiKey: '…',\n * walletAdapters: stellarWalletsKitAdapters({ network: Networks.PUBLIC }),\n * });\n * ```\n */\nexport function stellarWalletsKitAdapters(options: StellarWalletsKitAdapterOptions): WalletAdapter[] {\n // SSR / non-browser guard. Stellar Wallets Kit talks to browser wallet\n // extensions and touches `window` both at `StellarWalletsKit.init()` and in its\n // wallet modules' constructors — there are no wallets server-side, so return an\n // empty list instead of crashing during Next.js/Remix SSR. The real adapters\n // are built when this re-runs on the client (so build your PollarClient and\n // render the wallet UI on the client, e.g. behind a mounted flag or\n // `dynamic(..., { ssr: false })`).\n if (typeof window === 'undefined') return [];\n ensureInit(options);\n const modules = options.modules ?? buildDefaultModules();\n const wanted = options.picker?.wallets;\n return modules\n .filter((m) => !wanted || wanted.includes(m.productId))\n .map(\n (m) =>\n new StellarWalletsKitAdapter(m.productId, {\n label: options.picker?.labels?.[m.productId] ?? m.productName,\n iconUrl: m.productIcon,\n group: options.picker?.groupLabel ?? 'Wallet',\n }),\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 WalletAdapterMeta,\n WalletId,\n} from '@pollar/core';\nimport { getInitNetwork, getKitLogger } 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 readonly meta: WalletAdapterMeta;\n readonly custody = 'external' as const;\n private _address: string | null = null;\n\n constructor(walletId: WalletId, meta: WalletAdapterMeta) {\n this.type = walletId;\n this.meta = meta;\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 getKitLogger().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 };\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 // Mirror signTransaction's guard: the kit is a global singleton bound to one\n // network at init, so reject a per-call network override that doesn't match.\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.signAuthEntry(entryXdr, {\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedAuthEntry: result.signedAuthEntry };\n }\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -11,10 +11,15 @@ import { LobstrModule } from '@creit.tech/stellar-wallets-kit/modules/lobstr';
|
|
|
11
11
|
import { OneKeyModule } from '@creit.tech/stellar-wallets-kit/modules/onekey';
|
|
12
12
|
import { RabetModule } from '@creit.tech/stellar-wallets-kit/modules/rabet';
|
|
13
13
|
import { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';
|
|
14
|
+
import { createLogger } from '@pollar/core';
|
|
14
15
|
|
|
15
16
|
// src/StellarWalletsKitAdapter.ts
|
|
16
17
|
var initialised = false;
|
|
17
18
|
var initNetwork = null;
|
|
19
|
+
var _log = console;
|
|
20
|
+
function getKitLogger() {
|
|
21
|
+
return _log;
|
|
22
|
+
}
|
|
18
23
|
function buildDefaultModules() {
|
|
19
24
|
return [
|
|
20
25
|
new AlbedoModule(),
|
|
@@ -32,9 +37,12 @@ function buildDefaultModules() {
|
|
|
32
37
|
];
|
|
33
38
|
}
|
|
34
39
|
function ensureInit(options) {
|
|
40
|
+
if (options.logLevel !== void 0 || options.logger !== void 0) {
|
|
41
|
+
_log = createLogger(options.logLevel ?? "info", options.logger);
|
|
42
|
+
}
|
|
35
43
|
if (initialised) {
|
|
36
44
|
if (options.network && options.network !== initNetwork) {
|
|
37
|
-
|
|
45
|
+
_log.warn(
|
|
38
46
|
`[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.`
|
|
39
47
|
);
|
|
40
48
|
}
|
|
@@ -58,18 +66,27 @@ function getInitNetwork() {
|
|
|
58
66
|
}
|
|
59
67
|
return initNetwork;
|
|
60
68
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
function stellarWalletsKitAdapters(options) {
|
|
70
|
+
if (typeof window === "undefined") return [];
|
|
71
|
+
ensureInit(options);
|
|
72
|
+
const modules = options.modules ?? buildDefaultModules();
|
|
73
|
+
const wanted = options.picker?.wallets;
|
|
74
|
+
return modules.filter((m) => !wanted || wanted.includes(m.productId)).map(
|
|
75
|
+
(m) => new StellarWalletsKitAdapter(m.productId, {
|
|
76
|
+
label: options.picker?.labels?.[m.productId] ?? m.productName,
|
|
77
|
+
iconUrl: m.productIcon,
|
|
78
|
+
group: options.picker?.groupLabel ?? "Wallet"
|
|
79
|
+
})
|
|
80
|
+
);
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
// src/StellarWalletsKitAdapter.ts
|
|
69
84
|
var StellarWalletsKitAdapter = class {
|
|
70
|
-
constructor(walletId) {
|
|
85
|
+
constructor(walletId, meta) {
|
|
86
|
+
this.custody = "external";
|
|
71
87
|
this._address = null;
|
|
72
88
|
this.type = walletId;
|
|
89
|
+
this.meta = meta;
|
|
73
90
|
}
|
|
74
91
|
async isAvailable() {
|
|
75
92
|
try {
|
|
@@ -77,7 +94,7 @@ var StellarWalletsKitAdapter = class {
|
|
|
77
94
|
const wallet = supported.find((w) => w.id === String(this.type));
|
|
78
95
|
return wallet?.isAvailable ?? false;
|
|
79
96
|
} catch (err) {
|
|
80
|
-
|
|
97
|
+
getKitLogger().warn(`[StellarWalletsKit] isAvailable probe failed for "${this.type}"`, err);
|
|
81
98
|
return false;
|
|
82
99
|
}
|
|
83
100
|
}
|
|
@@ -120,6 +137,11 @@ var StellarWalletsKitAdapter = class {
|
|
|
120
137
|
return { signedTxXdr: result.signedTxXdr };
|
|
121
138
|
}
|
|
122
139
|
async signAuthEntry(entryXdr, options) {
|
|
140
|
+
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`[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.`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
123
145
|
StellarWalletsKit.setWallet(String(this.type));
|
|
124
146
|
const result = await StellarWalletsKit.signAuthEntry(entryXdr, {
|
|
125
147
|
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
@@ -128,6 +150,6 @@ var StellarWalletsKitAdapter = class {
|
|
|
128
150
|
}
|
|
129
151
|
};
|
|
130
152
|
|
|
131
|
-
export { StellarWalletsKitAdapter,
|
|
153
|
+
export { StellarWalletsKitAdapter, stellarWalletsKitAdapters };
|
|
132
154
|
//# sourceMappingURL=index.mjs.map
|
|
133
155
|
//# sourceMappingURL=index.mjs.map
|