@pollar/stellar-wallets-kit-adapter 0.10.1 → 0.11.2
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 +10 -4
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ The adapters are registered through the `walletAdapters` slot on `PollarClientCo
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @pollar/stellar-wallets-kit-adapter @creit.tech/stellar-wallets-kit
|
|
10
|
+
npm install @pollar/stellar-wallets-kit-adapter @pollar/core @creit.tech/stellar-wallets-kit
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
`@pollar/core` and `@creit.tech/stellar-wallets-kit` are peer dependencies — install whichever versions match the rest of your app. Requires Node 20+ when running in toolchains.
|
|
@@ -55,11 +55,16 @@ time (via `ensureInit()`), building one `StellarWalletsKitAdapter` per module up
|
|
|
55
55
|
front. It is not lazy - a later `login({ provider })` just routes to the
|
|
56
56
|
matching adapter that was already built.
|
|
57
57
|
|
|
58
|
+
> **0.11.2** requires `@pollar/core@^0.11.2` / `@pollar/react@^0.11.2`. The
|
|
59
|
+
> adapter now implements `signStellarMessage` (via `kit.signMessage`), so every
|
|
60
|
+
> kit wallet that supports message signing can back a SEP-53 ownership proof
|
|
61
|
+
> through `client.stellar.sep53`.
|
|
62
|
+
>
|
|
58
63
|
> **0.10.0** - switched to the `walletAdapters[]` array model: the factory is now
|
|
59
64
|
> `stellarWalletsKitAdapters()` (was `stellarWalletsKit()`) and returns a
|
|
60
65
|
> `WalletAdapter[]` for the plural `walletAdapters` config slot instead of a
|
|
61
66
|
> single resolver for `walletAdapter`. SSR-safe: returns `[]` when there is no
|
|
62
|
-
> `window`.
|
|
67
|
+
> `window`.
|
|
63
68
|
>
|
|
64
69
|
> `connect()` resolves to `{ address }` only, and `network` is **required** (no
|
|
65
70
|
> `Networks.TESTNET` default) — the kit is a global singleton, so silently
|
|
@@ -92,11 +97,12 @@ Calling `stellarWalletsKitAdapters({ network })` with no `modules` argument enab
|
|
|
92
97
|
Pass your own `modules` list. Import from the kit's per-wallet subpaths so unused modules tree-shake out:
|
|
93
98
|
|
|
94
99
|
```ts
|
|
100
|
+
import { PollarClient } from '@pollar/core';
|
|
95
101
|
import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
96
|
-
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
102
|
+
import { Networks, WalletNetwork } from '@creit.tech/stellar-wallets-kit';
|
|
97
103
|
import { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';
|
|
98
104
|
import { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';
|
|
99
|
-
import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
105
|
+
import { WalletConnectAllowedMethods, WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
100
106
|
|
|
101
107
|
const client = new PollarClient({
|
|
102
108
|
apiKey: 'your-api-key',
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletAdapter, WalletId, WalletAdapterMeta, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse, LogLevel, PollarLogger } from '@pollar/core';
|
|
1
|
+
import { WalletAdapter, WalletId, WalletAdapterMeta, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse, SignMessageOptions, SignMessageResponse, LogLevel, PollarLogger } from '@pollar/core';
|
|
2
2
|
import { Networks, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -19,6 +19,7 @@ declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
|
19
19
|
getPublicKey(): Promise<string | null>;
|
|
20
20
|
signTransaction(xdr: string, options?: SignTransactionOptions): Promise<SignTransactionResponse>;
|
|
21
21
|
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
22
|
+
signStellarMessage(message: string, options?: SignMessageOptions): Promise<SignMessageResponse>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletAdapter, WalletId, WalletAdapterMeta, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse, LogLevel, PollarLogger } from '@pollar/core';
|
|
1
|
+
import { WalletAdapter, WalletId, WalletAdapterMeta, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse, SignMessageOptions, SignMessageResponse, LogLevel, PollarLogger } from '@pollar/core';
|
|
2
2
|
import { Networks, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -19,6 +19,7 @@ declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
|
19
19
|
getPublicKey(): Promise<string | null>;
|
|
20
20
|
signTransaction(xdr: string, options?: SignTransactionOptions): Promise<SignTransactionResponse>;
|
|
21
21
|
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
22
|
+
signStellarMessage(message: string, options?: SignMessageOptions): Promise<SignMessageResponse>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/**
|
package/dist/index.js
CHANGED
|
@@ -52,7 +52,7 @@ function ensureInit(options) {
|
|
|
52
52
|
}
|
|
53
53
|
if (!options.network) {
|
|
54
54
|
throw new Error(
|
|
55
|
-
"[StellarWalletsKit] `network` is required \u2014 pass `Networks.TESTNET` or `Networks.PUBLIC` to `
|
|
55
|
+
"[StellarWalletsKit] `network` is required \u2014 pass `Networks.TESTNET` or `Networks.PUBLIC` to `stellarWalletsKitAdapters({ network })`. The kit is a global singleton, so the network has to be chosen explicitly at init."
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
stellarWalletsKit.StellarWalletsKit.init({
|
|
@@ -64,7 +64,7 @@ function ensureInit(options) {
|
|
|
64
64
|
}
|
|
65
65
|
function getInitNetwork() {
|
|
66
66
|
if (initNetwork === null) {
|
|
67
|
-
throw new Error("[StellarWalletsKit] not initialised \u2014 call `
|
|
67
|
+
throw new Error("[StellarWalletsKit] not initialised \u2014 call `stellarWalletsKitAdapters({ network })` first");
|
|
68
68
|
}
|
|
69
69
|
return initNetwork;
|
|
70
70
|
}
|
|
@@ -129,7 +129,7 @@ var StellarWalletsKitAdapter = class {
|
|
|
129
129
|
async signTransaction(xdr, options) {
|
|
130
130
|
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
131
131
|
throw new Error(
|
|
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 \`
|
|
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 \`stellarWalletsKitAdapters({ network })\` and use that for every call.`
|
|
133
133
|
);
|
|
134
134
|
}
|
|
135
135
|
stellarWalletsKit.StellarWalletsKit.setWallet(String(this.type));
|
|
@@ -141,7 +141,7 @@ var StellarWalletsKitAdapter = class {
|
|
|
141
141
|
async signAuthEntry(entryXdr, options) {
|
|
142
142
|
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
143
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 \`
|
|
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 \`stellarWalletsKitAdapters({ network })\` and use that for every call.`
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
147
|
stellarWalletsKit.StellarWalletsKit.setWallet(String(this.type));
|
|
@@ -150,6 +150,21 @@ var StellarWalletsKitAdapter = class {
|
|
|
150
150
|
});
|
|
151
151
|
return { signedAuthEntry: result.signedAuthEntry };
|
|
152
152
|
}
|
|
153
|
+
async signStellarMessage(message, options) {
|
|
154
|
+
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
`[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 \`stellarWalletsKitAdapters({ network })\` and use that for every call.`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
stellarWalletsKit.StellarWalletsKit.setWallet(String(this.type));
|
|
160
|
+
const result = await stellarWalletsKit.StellarWalletsKit.signMessage(message, {
|
|
161
|
+
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
signature: result.signedMessage,
|
|
165
|
+
...result.signerAddress !== void 0 && { signerAddress: result.signerAddress }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
153
168
|
};
|
|
154
169
|
|
|
155
170
|
exports.StellarWalletsKitAdapter = StellarWalletsKitAdapter;
|
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":";;;;;;;;;;;;;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O,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"]}
|
|
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;AAA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EAAG;AAC9F,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,gDAAA,EAAmD,OAAA,CAAQ,iBAAiB,CAAA,kDAAA,EAAqD,gBAAgB,CAAA,yIAAA;AAAA,OACnJ;AAAA,IACF;AACA,IAAAA,mCAAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAG7C,IAAA,MAAM,MAAA,GAAS,MAAMA,mCAAAA,CAAkB,WAAA,CAAY,OAAA,EAAS;AAAA,MAC1D,GAAI,OAAA,EAAS,aAAA,KAAkB,UAAa,EAAE,OAAA,EAAS,QAAQ,aAAA;AAAc,KAC9E,CAAA;AACD,IAAA,OAAO;AAAA,MACL,WAAW,MAAA,CAAO,aAAA;AAAA,MAClB,GAAI,MAAA,CAAO,aAAA,KAAkB,UAAa,EAAE,aAAA,EAAe,OAAO,aAAA;AAAc,KAClF;AAAA,EACF;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 * `stellarWalletsKitAdapters({ 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 `stellarWalletsKitAdapters({ 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 `stellarWalletsKitAdapters({ 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 SignMessageOptions,\n SignMessageResponse,\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 \\`stellarWalletsKitAdapters({ 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 \\`stellarWalletsKitAdapters({ 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 async signStellarMessage(message: string, options?: SignMessageOptions): Promise<SignMessageResponse> {\n // Same singleton network guard as the other signing paths.\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 \\`stellarWalletsKitAdapters({ network })\\` and use that for every call.`,\n );\n }\n StellarWalletsKit.setWallet(String(this.type));\n // The kit produces the SEP-53 signature natively and returns it as a base64\n // `signedMessage` plus the signer address.\n const result = await StellarWalletsKit.signMessage(message, {\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return {\n signature: result.signedMessage,\n ...(result.signerAddress !== undefined && { signerAddress: result.signerAddress }),\n };\n }\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -50,7 +50,7 @@ function ensureInit(options) {
|
|
|
50
50
|
}
|
|
51
51
|
if (!options.network) {
|
|
52
52
|
throw new Error(
|
|
53
|
-
"[StellarWalletsKit] `network` is required \u2014 pass `Networks.TESTNET` or `Networks.PUBLIC` to `
|
|
53
|
+
"[StellarWalletsKit] `network` is required \u2014 pass `Networks.TESTNET` or `Networks.PUBLIC` to `stellarWalletsKitAdapters({ network })`. The kit is a global singleton, so the network has to be chosen explicitly at init."
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
StellarWalletsKit.init({
|
|
@@ -62,7 +62,7 @@ function ensureInit(options) {
|
|
|
62
62
|
}
|
|
63
63
|
function getInitNetwork() {
|
|
64
64
|
if (initNetwork === null) {
|
|
65
|
-
throw new Error("[StellarWalletsKit] not initialised \u2014 call `
|
|
65
|
+
throw new Error("[StellarWalletsKit] not initialised \u2014 call `stellarWalletsKitAdapters({ network })` first");
|
|
66
66
|
}
|
|
67
67
|
return initNetwork;
|
|
68
68
|
}
|
|
@@ -127,7 +127,7 @@ var StellarWalletsKitAdapter = class {
|
|
|
127
127
|
async signTransaction(xdr, options) {
|
|
128
128
|
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
129
129
|
throw new Error(
|
|
130
|
-
`[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 \`
|
|
130
|
+
`[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 \`stellarWalletsKitAdapters({ network })\` and use that for every call.`
|
|
131
131
|
);
|
|
132
132
|
}
|
|
133
133
|
StellarWalletsKit.setWallet(String(this.type));
|
|
@@ -139,7 +139,7 @@ var StellarWalletsKitAdapter = class {
|
|
|
139
139
|
async signAuthEntry(entryXdr, options) {
|
|
140
140
|
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
141
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 \`
|
|
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 \`stellarWalletsKitAdapters({ network })\` and use that for every call.`
|
|
143
143
|
);
|
|
144
144
|
}
|
|
145
145
|
StellarWalletsKit.setWallet(String(this.type));
|
|
@@ -148,6 +148,21 @@ var StellarWalletsKitAdapter = class {
|
|
|
148
148
|
});
|
|
149
149
|
return { signedAuthEntry: result.signedAuthEntry };
|
|
150
150
|
}
|
|
151
|
+
async signStellarMessage(message, options) {
|
|
152
|
+
if (options?.networkPassphrase !== void 0 && options.networkPassphrase !== getInitNetwork()) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
`[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 \`stellarWalletsKitAdapters({ network })\` and use that for every call.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
StellarWalletsKit.setWallet(String(this.type));
|
|
158
|
+
const result = await StellarWalletsKit.signMessage(message, {
|
|
159
|
+
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
signature: result.signedMessage,
|
|
163
|
+
...result.signerAddress !== void 0 && { signerAddress: result.signerAddress }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
151
166
|
};
|
|
152
167
|
|
|
153
168
|
export { StellarWalletsKitAdapter, stellarWalletsKitAdapters };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/factory.ts","../src/StellarWalletsKitAdapter.ts"],"names":["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,IAAI,YAAA,EAAa;AAAA,IACjB,IAAI,YAAA,EAAa;AAAA,IACjB,IAAI,gBAAA,EAAiB;AAAA,IACrB,IAAI,aAAA,EAAc;AAAA,IAClB,IAAI,eAAA,EAAgB;AAAA,IACpB,IAAI,UAAA,EAAW;AAAA,IACf,IAAI,eAAA,EAAgB;AAAA,IACpB,IAAI,YAAA,EAAa;AAAA,IACjB,IAAI,YAAA,EAAa;AAAA,IACjB,IAAI,YAAA,EAAa;AAAA,IACjB,IAAI,WAAA,EAAY;AAAA,IAChB,IAAI,WAAA;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,GAAO,YAAA,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,OACl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,QACR,CAAA,gDAAA,EAAmD,OAAA,CAAQ,iBAAiB,CAAA,kDAAA,EAAqD,gBAAgB,CAAA,iIAAA;AAAA,OACnJ;AAAA,IACF;AACA,IAAAA,iBAAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAC7C,IAAA,MAAM,MAAA,GAAS,MAAMA,iBAAAA,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.mjs","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"]}
|
|
1
|
+
{"version":3,"sources":["../src/factory.ts","../src/StellarWalletsKitAdapter.ts"],"names":["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,IAAI,YAAA,EAAa;AAAA,IACjB,IAAI,YAAA,EAAa;AAAA,IACjB,IAAI,gBAAA,EAAiB;AAAA,IACrB,IAAI,aAAA,EAAc;AAAA,IAClB,IAAI,eAAA,EAAgB;AAAA,IACpB,IAAI,UAAA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Q,iBAAA,KAAsB,gBAAe,EAAG;AAC9F,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,gDAAA,EAAmD,OAAA,CAAQ,iBAAiB,CAAA,kDAAA,EAAqD,gBAAgB,CAAA,yIAAA;AAAA,OACnJ;AAAA,IACF;AACA,IAAAA,iBAAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAG7C,IAAA,MAAM,MAAA,GAAS,MAAMA,iBAAAA,CAAkB,WAAA,CAAY,OAAA,EAAS;AAAA,MAC1D,GAAI,OAAA,EAAS,aAAA,KAAkB,UAAa,EAAE,OAAA,EAAS,QAAQ,aAAA;AAAc,KAC9E,CAAA;AACD,IAAA,OAAO;AAAA,MACL,WAAW,MAAA,CAAO,aAAA;AAAA,MAClB,GAAI,MAAA,CAAO,aAAA,KAAkB,UAAa,EAAE,aAAA,EAAe,OAAO,aAAA;AAAc,KAClF;AAAA,EACF;AACF","file":"index.mjs","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 * `stellarWalletsKitAdapters({ 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 `stellarWalletsKitAdapters({ 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 `stellarWalletsKitAdapters({ 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 SignMessageOptions,\n SignMessageResponse,\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 \\`stellarWalletsKitAdapters({ 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 \\`stellarWalletsKitAdapters({ 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 async signStellarMessage(message: string, options?: SignMessageOptions): Promise<SignMessageResponse> {\n // Same singleton network guard as the other signing paths.\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 \\`stellarWalletsKitAdapters({ network })\\` and use that for every call.`,\n );\n }\n StellarWalletsKit.setWallet(String(this.type));\n // The kit produces the SEP-53 signature natively and returns it as a base64\n // `signedMessage` plus the signer address.\n const result = await StellarWalletsKit.signMessage(message, {\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return {\n signature: result.signedMessage,\n ...(result.signerAddress !== undefined && { signerAddress: result.signerAddress }),\n };\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pollar/stellar-wallets-kit-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.2",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/pollar-xyz/pollar.git",
|
|
8
|
+
"directory": "packages/stellar-wallets-kit-adapter"
|
|
9
|
+
},
|
|
4
10
|
"description": "Stellar Wallets Kit adapter for @pollar/core — plug additional wallet modules (xBull, Lobstr, WalletConnect, hardware wallets…) into Pollar without bundling them into @pollar/core.",
|
|
5
11
|
"main": "./dist/index.js",
|
|
6
12
|
"module": "./dist/index.mjs",
|
|
@@ -32,10 +38,10 @@
|
|
|
32
38
|
},
|
|
33
39
|
"peerDependencies": {
|
|
34
40
|
"@creit.tech/stellar-wallets-kit": "^2.0.0",
|
|
35
|
-
"@pollar/core": "^0.
|
|
41
|
+
"@pollar/core": "^0.11.2"
|
|
36
42
|
},
|
|
37
43
|
"dependencies": {
|
|
38
|
-
"@pollar/core": "^0.
|
|
44
|
+
"@pollar/core": "^0.11.2"
|
|
39
45
|
},
|
|
40
46
|
"devDependencies": {
|
|
41
47
|
"@creit.tech/stellar-wallets-kit": "^2.3.0",
|