@pollar/stellar-wallets-kit-adapter 0.9.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 CHANGED
@@ -182,71 +182,32 @@ The adapter implements `WalletAdapter` from `@pollar/core`:
182
182
 
183
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.
184
184
 
185
- ## Wallet picker UI (`/picker`)
185
+ ## Login UI
186
186
 
187
- The `/picker` subpath ships a React component that renders the kit's full
188
- wallet list inside Pollar's `LoginModal`. It plugs into the
189
- `ui.renderWallets` slot on `<PollarProvider>` (new in `@pollar/react@0.8.0`).
190
-
191
- > **React is an optional peer dep.** Only the `/picker` subpath pulls in
192
- > `react` / `react-dom` / `@pollar/react`. Headless consumers of
193
- > `stellarWalletsKit({ network })` keep working with zero React in the bundle.
194
-
195
- ### Bundle helper
196
-
197
- `createStellarWalletsKitBundle` builds both halves of the integration
198
- (signing resolver + picker slot) from a single options object, so the picker
199
- can only show wallets that signing actually supports:
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.
200
192
 
201
193
  ```tsx
202
194
  import { PollarProvider } from '@pollar/react';
203
- import { createStellarWalletsKitBundle } from '@pollar/stellar-wallets-kit-adapter/picker';
204
- import { Networks } from '@creit.tech/stellar-wallets-kit';
205
-
206
- const bundle = createStellarWalletsKitBundle({
207
- network: Networks.PUBLIC,
208
- // Optional — subset, order, layout, theme, labels: see `KitPickerOptions`
209
- picker: { wallets: ['xbull', 'lobstr', 'freighter'], layout: 'list' },
210
- });
211
-
212
- <PollarProvider
213
- client={{ apiKey: 'your-api-key', walletAdapter: bundle.walletAdapter }}
214
- ui={{ renderWallets: bundle.renderWallets }}
215
- >
216
- {/* your app */}
217
- </PollarProvider>;
218
- ```
219
-
220
- ### Picker component directly
221
-
222
- If you already build the `walletAdapter` yourself (e.g. composing a custom
223
- resolver), use `<KitWalletPicker>` directly inside a `renderWallets` slot:
224
-
225
- ```tsx
226
- import { KitWalletPicker } from '@pollar/stellar-wallets-kit-adapter/picker';
195
+ import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
227
196
  import { Networks } from '@creit.tech/stellar-wallets-kit';
228
197
 
229
198
  <PollarProvider
230
- client={{ apiKey: '…', walletAdapter: myResolver }}
231
- ui={{
232
- renderWallets: ({ onConnect, authState }) => (
233
- <KitWalletPicker
234
- onConnect={onConnect}
235
- authState={authState}
236
- network={Networks.PUBLIC}
237
- picker={{ wallets: ['xbull', 'lobstr'], showInstalledOnly: true }}
238
- />
239
- ),
199
+ client={{
200
+ apiKey: 'your-api-key',
201
+ walletAdapters: stellarWalletsKitAdapters({
202
+ network: Networks.PUBLIC,
203
+ picker: { wallets: ['xbull', 'lobstr', 'freighter'] },
204
+ }),
240
205
  }}
241
206
  >
242
- {children}
207
+ {/* your app */}
243
208
  </PollarProvider>;
244
209
  ```
245
210
 
246
- `<KitWalletPicker>` will lazily call `ensureInit({ network, modules })` on
247
- mount, so it works whether or not `stellarWalletsKit(...)` has already been
248
- called elsewhere — both share the same kit singleton.
249
-
250
211
  ## Direct adapter access
251
212
 
252
213
  If you need a `WalletAdapter` instance directly (custom flows outside `PollarClient`), instantiate it yourself once the kit is initialized:
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
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-CR-sDzIv.mjs';
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
- export { StellarWalletsKitAdapter };
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
- export { K as KitPickerOptions, S as StellarWalletsKitAdapterOptions, s as stellarWalletsKit } from './factory-CR-sDzIv.js';
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
- export { StellarWalletsKitAdapter };
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$1 = require('@creit.tech/stellar-wallets-kit');
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');
@@ -55,7 +55,7 @@ function ensureInit(options) {
55
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."
56
56
  );
57
57
  }
58
- stellarWalletsKit$1.StellarWalletsKit.init({
58
+ stellarWalletsKit.StellarWalletsKit.init({
59
59
  network: options.network,
60
60
  modules: options.modules ?? buildDefaultModules()
61
61
  });
@@ -68,22 +68,31 @@ function getInitNetwork() {
68
68
  }
69
69
  return initNetwork;
70
70
  }
71
- function stellarWalletsKit(options) {
72
- return (id) => {
73
- ensureInit(options);
74
- return new StellarWalletsKitAdapter(id);
75
- };
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
+ );
76
83
  }
77
84
 
78
85
  // src/StellarWalletsKitAdapter.ts
79
86
  var StellarWalletsKitAdapter = class {
80
- constructor(walletId) {
87
+ constructor(walletId, meta) {
88
+ this.custody = "external";
81
89
  this._address = null;
82
90
  this.type = walletId;
91
+ this.meta = meta;
83
92
  }
84
93
  async isAvailable() {
85
94
  try {
86
- const supported = await stellarWalletsKit$1.StellarWalletsKit.refreshSupportedWallets();
95
+ const supported = await stellarWalletsKit.StellarWalletsKit.refreshSupportedWallets();
87
96
  const wallet = supported.find((w) => w.id === String(this.type));
88
97
  return wallet?.isAvailable ?? false;
89
98
  } catch (err) {
@@ -92,8 +101,8 @@ var StellarWalletsKitAdapter = class {
92
101
  }
93
102
  }
94
103
  async connect() {
95
- stellarWalletsKit$1.StellarWalletsKit.setWallet(String(this.type));
96
- const { address } = await stellarWalletsKit$1.StellarWalletsKit.fetchAddress();
104
+ stellarWalletsKit.StellarWalletsKit.setWallet(String(this.type));
105
+ const { address } = await stellarWalletsKit.StellarWalletsKit.fetchAddress();
97
106
  if (!address) {
98
107
  throw new Error(`[StellarWalletsKit] Empty address returned for wallet "${this.type}"`);
99
108
  }
@@ -102,7 +111,7 @@ var StellarWalletsKitAdapter = class {
102
111
  }
103
112
  async disconnect() {
104
113
  try {
105
- await stellarWalletsKit$1.StellarWalletsKit.disconnect();
114
+ await stellarWalletsKit.StellarWalletsKit.disconnect();
106
115
  } finally {
107
116
  this._address = null;
108
117
  }
@@ -110,7 +119,7 @@ var StellarWalletsKitAdapter = class {
110
119
  async getPublicKey() {
111
120
  if (this._address) return this._address;
112
121
  try {
113
- const { address } = await stellarWalletsKit$1.StellarWalletsKit.getAddress();
122
+ const { address } = await stellarWalletsKit.StellarWalletsKit.getAddress();
114
123
  this._address = address ?? null;
115
124
  return this._address;
116
125
  } catch {
@@ -123,15 +132,20 @@ var StellarWalletsKitAdapter = class {
123
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.`
124
133
  );
125
134
  }
126
- stellarWalletsKit$1.StellarWalletsKit.setWallet(String(this.type));
127
- const result = await stellarWalletsKit$1.StellarWalletsKit.signTransaction(xdr, {
135
+ stellarWalletsKit.StellarWalletsKit.setWallet(String(this.type));
136
+ const result = await stellarWalletsKit.StellarWalletsKit.signTransaction(xdr, {
128
137
  ...options?.accountToSign !== void 0 && { address: options.accountToSign }
129
138
  });
130
139
  return { signedTxXdr: result.signedTxXdr };
131
140
  }
132
141
  async signAuthEntry(entryXdr, options) {
133
- stellarWalletsKit$1.StellarWalletsKit.setWallet(String(this.type));
134
- const result = await stellarWalletsKit$1.StellarWalletsKit.signAuthEntry(entryXdr, {
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, {
135
149
  ...options?.accountToSign !== void 0 && { address: options.accountToSign }
136
150
  });
137
151
  return { signedAuthEntry: result.signedAuthEntry };
@@ -139,6 +153,6 @@ var StellarWalletsKitAdapter = class {
139
153
  };
140
154
 
141
155
  exports.StellarWalletsKitAdapter = StellarWalletsKitAdapter;
142
- exports.stellarWalletsKit = stellarWalletsKit;
156
+ exports.stellarWalletsKitAdapters = stellarWalletsKitAdapters;
143
157
  //# sourceMappingURL=index.js.map
144
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","createLogger","StellarWalletsKit"],"mappings":";;;;;;;;;;;;;;;;;;AA2EA,IAAI,WAAA,GAAc,KAAA;AAClB,I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AAS,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 { createLogger, type LogLevel, type PollarLogger, type WalletAdapterResolver, type 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 * 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 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, 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 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 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 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,IACF;AACA,IAAA;AAAA,EACF;A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AQ,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
@@ -66,18 +66,27 @@ function getInitNetwork() {
66
66
  }
67
67
  return initNetwork;
68
68
  }
69
- function stellarWalletsKit(options) {
70
- return (id) => {
71
- ensureInit(options);
72
- return new StellarWalletsKitAdapter(id);
73
- };
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
+ );
74
81
  }
75
82
 
76
83
  // src/StellarWalletsKitAdapter.ts
77
84
  var StellarWalletsKitAdapter = class {
78
- constructor(walletId) {
85
+ constructor(walletId, meta) {
86
+ this.custody = "external";
79
87
  this._address = null;
80
88
  this.type = walletId;
89
+ this.meta = meta;
81
90
  }
82
91
  async isAvailable() {
83
92
  try {
@@ -128,6 +137,11 @@ var StellarWalletsKitAdapter = class {
128
137
  return { signedTxXdr: result.signedTxXdr };
129
138
  }
130
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
+ }
131
145
  StellarWalletsKit.setWallet(String(this.type));
132
146
  const result = await StellarWalletsKit.signAuthEntry(entryXdr, {
133
147
  ...options?.accountToSign !== void 0 && { address: options.accountToSign }
@@ -136,6 +150,6 @@ var StellarWalletsKitAdapter = class {
136
150
  }
137
151
  };
138
152
 
139
- export { StellarWalletsKitAdapter, stellarWalletsKit };
153
+ export { StellarWalletsKitAdapter, stellarWalletsKitAdapters };
140
154
  //# sourceMappingURL=index.mjs.map
141
155
  //# sourceMappingURL=index.mjs.map