@pollar/stellar-wallets-kit-adapter 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -0
- package/dist/index.d.mts +60 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +105 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# @pollar/stellar-wallets-kit-adapter
|
|
2
|
+
|
|
3
|
+
Plug [Stellar Wallets Kit](https://stellarwalletskit.dev) into [`@pollar/core`](../core) as a single wallet adapter, without `@pollar/core` having to depend on the kit. One install gives Pollar access to **every wallet module the kit supports** — Freighter, Albedo, xBull, Lobstr, Rabet, Hana, Bitget, OneKey, Klever, Fordefi, CactusLink, HotWallet, plus Ledger / Trezor / WalletConnect via opt-in.
|
|
4
|
+
|
|
5
|
+
The adapter is consumed through the `walletAdapter` slot on `PollarClientConfig`, so swapping wallet stacks (built-in adapters → kit, kit → custom resolver) is a one-line change.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @pollar/stellar-wallets-kit-adapter @creit.tech/stellar-wallets-kit
|
|
11
|
+
```
|
|
12
|
+
|
|
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.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { PollarClient } from '@pollar/core';
|
|
19
|
+
import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
20
|
+
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
21
|
+
|
|
22
|
+
const client = new PollarClient({
|
|
23
|
+
apiKey: 'your-api-key',
|
|
24
|
+
walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Triggers the kit's flow for the picked wallet id
|
|
28
|
+
client.loginWallet('xbull');
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
With React:
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { PollarProvider } from '@pollar/react';
|
|
35
|
+
import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
36
|
+
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
37
|
+
|
|
38
|
+
<PollarProvider
|
|
39
|
+
config={{
|
|
40
|
+
apiKey: 'your-api-key',
|
|
41
|
+
walletAdapter: stellarWalletsKit({ network: Networks.TESTNET }),
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
{/* your app */}
|
|
45
|
+
</PollarProvider>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The kit is a global singleton. `stellarWalletsKit(...)` returns a resolver and `StellarWalletsKit.init(...)` is called once on the first `loginWallet` call.
|
|
49
|
+
|
|
50
|
+
## Default wallets
|
|
51
|
+
|
|
52
|
+
Calling `stellarWalletsKit()` with no `modules` argument enables every module that loads without extra configuration:
|
|
53
|
+
|
|
54
|
+
| Module | Wallet id (`WalletId`) | Type |
|
|
55
|
+
| --------------- | ---------------------- | -------------------- |
|
|
56
|
+
| `AlbedoModule` | `albedo` | Web |
|
|
57
|
+
| `BitgetModule` | `bitget` | Browser extension |
|
|
58
|
+
| `CactusLinkModule` | `cactuslink` | Browser extension |
|
|
59
|
+
| `FordefiModule` | `fordefi` | Browser extension |
|
|
60
|
+
| `FreighterModule` | `freighter` | Browser extension |
|
|
61
|
+
| `HanaModule` | `hana` | Browser extension |
|
|
62
|
+
| `HotWalletModule` | `hotwallet` | Mobile / deep link |
|
|
63
|
+
| `KleverModule` | `klever` | Browser extension |
|
|
64
|
+
| `LobstrModule` | `lobstr` | Mobile / deep link |
|
|
65
|
+
| `OneKeyModule` | `onekey` | Browser extension |
|
|
66
|
+
| `RabetModule` | `rabet` | Browser extension |
|
|
67
|
+
| `xBullModule` | `xbull` | Browser extension |
|
|
68
|
+
|
|
69
|
+
> **Why not Ledger / Trezor / WalletConnect by default?** Ledger needs a `Buffer` polyfill in the host app (loading it unconditionally would crash bundles that don't ship one). Trezor and WalletConnect require constructor parameters (Trezor manifest, WalletConnect project id). All three stay opt-in.
|
|
70
|
+
|
|
71
|
+
## Adding extra wallets
|
|
72
|
+
|
|
73
|
+
Pass your own `modules` list. Import from the kit's per-wallet subpaths so unused modules tree-shake out:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
77
|
+
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
78
|
+
import { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';
|
|
79
|
+
import { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';
|
|
80
|
+
import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
81
|
+
|
|
82
|
+
const client = new PollarClient({
|
|
83
|
+
apiKey: 'your-api-key',
|
|
84
|
+
walletAdapter: stellarWalletsKit({
|
|
85
|
+
network: Networks.PUBLIC,
|
|
86
|
+
modules: [
|
|
87
|
+
new FreighterModule(),
|
|
88
|
+
new xBullModule(),
|
|
89
|
+
new WalletConnectModule({
|
|
90
|
+
url: 'https://example.com',
|
|
91
|
+
projectId: 'your-walletconnect-project-id',
|
|
92
|
+
method: WalletConnectAllowedMethods.SIGN,
|
|
93
|
+
description: 'Sign in to Example with Stellar',
|
|
94
|
+
name: 'Example',
|
|
95
|
+
icons: ['https://example.com/icon.png'],
|
|
96
|
+
network: WalletNetwork.PUBLIC,
|
|
97
|
+
}),
|
|
98
|
+
],
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Trimming the default list (e.g. only Freighter + Albedo for a SEP-43 dapp) works the same way — `modules` fully replaces the default when supplied.
|
|
104
|
+
|
|
105
|
+
## Configuration
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
interface StellarWalletsKitAdapterOptions {
|
|
109
|
+
/** Stellar network used for signing. Defaults to `Networks.TESTNET`. */
|
|
110
|
+
network?: Networks;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Wallet modules the kit can drive. Defaults to every module that works
|
|
114
|
+
* with no extra setup (see "Default wallets"). Passing this option fully
|
|
115
|
+
* replaces the default — include modules you want explicitly.
|
|
116
|
+
*/
|
|
117
|
+
modules?: ModuleInterface[];
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The factory returns a `WalletAdapterResolver` from `@pollar/core`:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
type WalletAdapterResolver = (id: WalletId) => WalletAdapter | Promise<WalletAdapter>;
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`WalletId` is `WalletType | (string & {})` — `WalletType.FREIGHTER` / `WalletType.ALBEDO` keep autocomplete, every other kit id (`'xbull'`, `'lobstr'`, …) is accepted as a plain string.
|
|
128
|
+
|
|
129
|
+
## How it fits the Pollar wallet contract
|
|
130
|
+
|
|
131
|
+
The adapter implements `WalletAdapter` from `@pollar/core`:
|
|
132
|
+
|
|
133
|
+
| `WalletAdapter` method | Kit call |
|
|
134
|
+
| ---------------------------- | ----------------------------------------------- |
|
|
135
|
+
| `isAvailable()` | `StellarWalletsKit.setWallet(id)` |
|
|
136
|
+
| `connect()` | `setWallet(id)` → `fetchAddress()` |
|
|
137
|
+
| `disconnect()` | `StellarWalletsKit.disconnect()` |
|
|
138
|
+
| `getPublicKey()` | `StellarWalletsKit.getAddress()` |
|
|
139
|
+
| `signTransaction(xdr, opts)` | `setWallet(id)` → `signTransaction(xdr, opts)` |
|
|
140
|
+
| `signAuthEntry(xdr, opts)` | `setWallet(id)` → `signAuthEntry(xdr, opts)` |
|
|
141
|
+
|
|
142
|
+
`setWallet` is called before every operation so a single `StellarWalletsKit.init({ modules })` covers many wallets — `PollarClient` resolves a fresh adapter instance per `WalletId`, and the kit routes to the correct module under the hood.
|
|
143
|
+
|
|
144
|
+
## Direct adapter access
|
|
145
|
+
|
|
146
|
+
If you need a `WalletAdapter` instance directly (custom flows outside `PollarClient`), instantiate it yourself once the kit is initialized:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { StellarWalletsKit, Networks } from '@creit.tech/stellar-wallets-kit';
|
|
150
|
+
import { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';
|
|
151
|
+
import { StellarWalletsKitAdapter } from '@pollar/stellar-wallets-kit-adapter';
|
|
152
|
+
|
|
153
|
+
StellarWalletsKit.init({ network: Networks.PUBLIC, modules: [new FreighterModule()] });
|
|
154
|
+
|
|
155
|
+
const adapter = new StellarWalletsKitAdapter('freighter');
|
|
156
|
+
const { publicKey } = await adapter.connect();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Writing a custom resolver
|
|
160
|
+
|
|
161
|
+
`walletAdapter` accepts any function matching `WalletAdapterResolver`. Use this to swap between the kit and your own implementation per-id, or to compose multiple adapter packages:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
165
|
+
import { FreighterAdapter, WalletType } from '@pollar/core';
|
|
166
|
+
|
|
167
|
+
const kit = stellarWalletsKit({ network: Networks.PUBLIC });
|
|
168
|
+
|
|
169
|
+
new PollarClient({
|
|
170
|
+
apiKey: 'your-api-key',
|
|
171
|
+
walletAdapter: (id) => {
|
|
172
|
+
// Use the in-house Freighter adapter, kit for everything else
|
|
173
|
+
if (id === WalletType.FREIGHTER) return new FreighterAdapter();
|
|
174
|
+
return kit(id);
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Fallback behaviour
|
|
180
|
+
|
|
181
|
+
If `walletAdapter` is omitted from `PollarClientConfig`, `@pollar/core` falls back to its built-in `FreighterAdapter` / `AlbedoAdapter`. Installing this package is opt-in — existing apps keep working without changes until they switch the slot.
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { WalletAdapter, WalletId, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse, WalletAdapterResolver } from '@pollar/core';
|
|
2
|
+
import { Networks, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`
|
|
6
|
+
* contract. The kit is a global singleton — `setWallet` is called before every
|
|
7
|
+
* operation so the correct module handles the request, which lets a single
|
|
8
|
+
* `StellarWalletsKit.init(...)` cover many wallet modules.
|
|
9
|
+
*/
|
|
10
|
+
declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
11
|
+
readonly type: WalletId;
|
|
12
|
+
private _address;
|
|
13
|
+
constructor(walletId: WalletId);
|
|
14
|
+
isAvailable(): Promise<boolean>;
|
|
15
|
+
connect(): Promise<ConnectWalletResponse>;
|
|
16
|
+
disconnect(): Promise<void>;
|
|
17
|
+
getPublicKey(): Promise<string | null>;
|
|
18
|
+
signTransaction(xdr: string, options?: SignTransactionOptions): Promise<SignTransactionResponse>;
|
|
19
|
+
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface StellarWalletsKitAdapterOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Stellar network the kit will use for signing. Defaults to `Networks.TESTNET`.
|
|
25
|
+
*/
|
|
26
|
+
network?: Networks;
|
|
27
|
+
/**
|
|
28
|
+
* Wallet modules the kit should drive. Defaults to every module that works
|
|
29
|
+
* out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,
|
|
30
|
+
* HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list
|
|
31
|
+
* to add Ledger / Trezor / WalletConnect — those need extra setup (a
|
|
32
|
+
* Buffer polyfill for Ledger; constructor params for the other two) so we
|
|
33
|
+
* don't auto-include them.
|
|
34
|
+
*
|
|
35
|
+
* Import modules from their kit subpaths so the bundle stays lean:
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
modules?: ModuleInterface[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass
|
|
44
|
+
* the result to `PollarClientConfig.walletAdapter` so Pollar can use any of
|
|
45
|
+
* the kit's modules without `@pollar/core` having to depend on the kit.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
50
|
+
* import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
51
|
+
*
|
|
52
|
+
* const client = new PollarClient({
|
|
53
|
+
* apiKey: '…',
|
|
54
|
+
* walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function stellarWalletsKit(options?: StellarWalletsKitAdapterOptions): WalletAdapterResolver;
|
|
59
|
+
|
|
60
|
+
export { StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, stellarWalletsKit };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { WalletAdapter, WalletId, ConnectWalletResponse, SignTransactionOptions, SignTransactionResponse, SignAuthEntryOptions, SignAuthEntryResponse, WalletAdapterResolver } from '@pollar/core';
|
|
2
|
+
import { Networks, ModuleInterface } from '@creit.tech/stellar-wallets-kit';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`
|
|
6
|
+
* contract. The kit is a global singleton — `setWallet` is called before every
|
|
7
|
+
* operation so the correct module handles the request, which lets a single
|
|
8
|
+
* `StellarWalletsKit.init(...)` cover many wallet modules.
|
|
9
|
+
*/
|
|
10
|
+
declare class StellarWalletsKitAdapter implements WalletAdapter {
|
|
11
|
+
readonly type: WalletId;
|
|
12
|
+
private _address;
|
|
13
|
+
constructor(walletId: WalletId);
|
|
14
|
+
isAvailable(): Promise<boolean>;
|
|
15
|
+
connect(): Promise<ConnectWalletResponse>;
|
|
16
|
+
disconnect(): Promise<void>;
|
|
17
|
+
getPublicKey(): Promise<string | null>;
|
|
18
|
+
signTransaction(xdr: string, options?: SignTransactionOptions): Promise<SignTransactionResponse>;
|
|
19
|
+
signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface StellarWalletsKitAdapterOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Stellar network the kit will use for signing. Defaults to `Networks.TESTNET`.
|
|
25
|
+
*/
|
|
26
|
+
network?: Networks;
|
|
27
|
+
/**
|
|
28
|
+
* Wallet modules the kit should drive. Defaults to every module that works
|
|
29
|
+
* out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,
|
|
30
|
+
* HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list
|
|
31
|
+
* to add Ledger / Trezor / WalletConnect — those need extra setup (a
|
|
32
|
+
* Buffer polyfill for Ledger; constructor params for the other two) so we
|
|
33
|
+
* don't auto-include them.
|
|
34
|
+
*
|
|
35
|
+
* Import modules from their kit subpaths so the bundle stays lean:
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
modules?: ModuleInterface[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass
|
|
44
|
+
* the result to `PollarClientConfig.walletAdapter` so Pollar can use any of
|
|
45
|
+
* the kit's modules without `@pollar/core` having to depend on the kit.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';
|
|
50
|
+
* import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
51
|
+
*
|
|
52
|
+
* const client = new PollarClient({
|
|
53
|
+
* apiKey: '…',
|
|
54
|
+
* walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function stellarWalletsKit(options?: StellarWalletsKitAdapterOptions): WalletAdapterResolver;
|
|
59
|
+
|
|
60
|
+
export { StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, stellarWalletsKit };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stellarWalletsKit$1 = require('@creit.tech/stellar-wallets-kit');
|
|
4
|
+
var albedo = require('@creit.tech/stellar-wallets-kit/modules/albedo');
|
|
5
|
+
var bitget = require('@creit.tech/stellar-wallets-kit/modules/bitget');
|
|
6
|
+
var cactuslink = require('@creit.tech/stellar-wallets-kit/modules/cactuslink');
|
|
7
|
+
var fordefi = require('@creit.tech/stellar-wallets-kit/modules/fordefi');
|
|
8
|
+
var freighter = require('@creit.tech/stellar-wallets-kit/modules/freighter');
|
|
9
|
+
var hana = require('@creit.tech/stellar-wallets-kit/modules/hana');
|
|
10
|
+
var hotwallet = require('@creit.tech/stellar-wallets-kit/modules/hotwallet');
|
|
11
|
+
var klever = require('@creit.tech/stellar-wallets-kit/modules/klever');
|
|
12
|
+
var lobstr = require('@creit.tech/stellar-wallets-kit/modules/lobstr');
|
|
13
|
+
var onekey = require('@creit.tech/stellar-wallets-kit/modules/onekey');
|
|
14
|
+
var rabet = require('@creit.tech/stellar-wallets-kit/modules/rabet');
|
|
15
|
+
var xbull = require('@creit.tech/stellar-wallets-kit/modules/xbull');
|
|
16
|
+
|
|
17
|
+
// src/StellarWalletsKitAdapter.ts
|
|
18
|
+
var StellarWalletsKitAdapter = class {
|
|
19
|
+
constructor(walletId) {
|
|
20
|
+
this._address = null;
|
|
21
|
+
this.type = walletId;
|
|
22
|
+
}
|
|
23
|
+
async isAvailable() {
|
|
24
|
+
try {
|
|
25
|
+
stellarWalletsKit$1.StellarWalletsKit.setWallet(String(this.type));
|
|
26
|
+
return true;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async connect() {
|
|
32
|
+
stellarWalletsKit$1.StellarWalletsKit.setWallet(String(this.type));
|
|
33
|
+
const { address } = await stellarWalletsKit$1.StellarWalletsKit.fetchAddress();
|
|
34
|
+
if (!address) {
|
|
35
|
+
throw new Error(`[StellarWalletsKit] Empty address returned for wallet "${this.type}"`);
|
|
36
|
+
}
|
|
37
|
+
this._address = address;
|
|
38
|
+
return { address, publicKey: address };
|
|
39
|
+
}
|
|
40
|
+
async disconnect() {
|
|
41
|
+
try {
|
|
42
|
+
await stellarWalletsKit$1.StellarWalletsKit.disconnect();
|
|
43
|
+
} finally {
|
|
44
|
+
this._address = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async getPublicKey() {
|
|
48
|
+
if (this._address) return this._address;
|
|
49
|
+
try {
|
|
50
|
+
const { address } = await stellarWalletsKit$1.StellarWalletsKit.getAddress();
|
|
51
|
+
this._address = address ?? null;
|
|
52
|
+
return this._address;
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async signTransaction(xdr, options) {
|
|
58
|
+
stellarWalletsKit$1.StellarWalletsKit.setWallet(String(this.type));
|
|
59
|
+
const result = await stellarWalletsKit$1.StellarWalletsKit.signTransaction(xdr, {
|
|
60
|
+
...options?.networkPassphrase !== void 0 && { networkPassphrase: options.networkPassphrase },
|
|
61
|
+
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
62
|
+
});
|
|
63
|
+
return { signedTxXdr: result.signedTxXdr };
|
|
64
|
+
}
|
|
65
|
+
async signAuthEntry(entryXdr, options) {
|
|
66
|
+
stellarWalletsKit$1.StellarWalletsKit.setWallet(String(this.type));
|
|
67
|
+
const result = await stellarWalletsKit$1.StellarWalletsKit.signAuthEntry(entryXdr, {
|
|
68
|
+
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
69
|
+
});
|
|
70
|
+
return { signedAuthEntry: result.signedAuthEntry };
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var initialised = false;
|
|
74
|
+
function buildDefaultModules() {
|
|
75
|
+
return [
|
|
76
|
+
new albedo.AlbedoModule(),
|
|
77
|
+
new bitget.BitgetModule(),
|
|
78
|
+
new cactuslink.CactusLinkModule(),
|
|
79
|
+
new fordefi.FordefiModule(),
|
|
80
|
+
new freighter.FreighterModule(),
|
|
81
|
+
new hana.HanaModule(),
|
|
82
|
+
new hotwallet.HotWalletModule(),
|
|
83
|
+
new klever.KleverModule(),
|
|
84
|
+
new lobstr.LobstrModule(),
|
|
85
|
+
new onekey.OneKeyModule(),
|
|
86
|
+
new rabet.RabetModule(),
|
|
87
|
+
new xbull.xBullModule()
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
function ensureInit(options) {
|
|
91
|
+
if (initialised) return;
|
|
92
|
+
stellarWalletsKit$1.StellarWalletsKit.init({
|
|
93
|
+
network: options.network ?? stellarWalletsKit$1.Networks.TESTNET,
|
|
94
|
+
modules: options.modules ?? buildDefaultModules()
|
|
95
|
+
});
|
|
96
|
+
initialised = true;
|
|
97
|
+
}
|
|
98
|
+
function stellarWalletsKit(options = {}) {
|
|
99
|
+
return (id) => {
|
|
100
|
+
ensureInit(options);
|
|
101
|
+
return new StellarWalletsKitAdapter(id);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.StellarWalletsKitAdapter = StellarWalletsKitAdapter;
|
|
106
|
+
exports.stellarWalletsKit = stellarWalletsKit;
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/StellarWalletsKitAdapter.ts","../src/factory.ts"],"names":["StellarWalletsKit","AlbedoModule","BitgetModule","CactusLinkModule","FordefiModule","FreighterModule","HanaModule","HotWalletModule","KleverModule","LobstrModule","OneKeyModule","RabetModule","xBullModule","Networks"],"mappings":";;;;;;;;;;;;;;;;;AAiBO,IAAM,2BAAN,MAAwD;AAAA,EAI7D,YAAY,QAAA,EAAoB;AAFhC,IAAA,IAAA,CAAQ,QAAA,GAA0B,IAAA;AAGhC,IAAA,IAAA,CAAK,IAAA,GAAO,QAAA;AAAA,EACd;AAAA,EAEA,MAAM,WAAA,GAAgC;AACpC,IAAA,IAAI;AACF,MAAAA,qCAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAK7C,MAAA,OAAO,IAAA;AAAA,IACT,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,OAAA,GAA0C;AAC9C,IAAAA,qCAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAC7C,IAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAMA,sCAAkB,YAAA,EAAa;AACzD,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,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;AAClB,IAAA,OAAO,IAAI,yBAAyB,EAAE,CAAA;AAAA,EACxC,CAAA;AACF","file":"index.js","sourcesContent":["import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';\nimport type {\n ConnectWalletResponse,\n SignAuthEntryOptions,\n SignAuthEntryResponse,\n SignTransactionOptions,\n SignTransactionResponse,\n WalletAdapter,\n WalletId,\n} from '@pollar/core';\n\n/**\n * Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`\n * contract. The kit is a global singleton — `setWallet` is called before every\n * operation so the correct module handles the request, which lets a single\n * `StellarWalletsKit.init(...)` cover many wallet modules.\n */\nexport class StellarWalletsKitAdapter implements WalletAdapter {\n readonly type: WalletId;\n private _address: string | null = null;\n\n constructor(walletId: WalletId) {\n this.type = walletId;\n }\n\n async isAvailable(): Promise<boolean> {\n try {\n StellarWalletsKit.setWallet(String(this.type));\n // The kit doesn't expose a top-level `isAvailable`; once the module is\n // selected, attempting an address fetch is the cheapest probe — but it\n // can pop UI on some wallets. Return true and let `connect()` surface\n // the real availability error if any.\n return true;\n } catch {\n return false;\n }\n }\n\n async connect(): Promise<ConnectWalletResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const { address } = await StellarWalletsKit.fetchAddress();\n if (!address) {\n throw new Error(`[StellarWalletsKit] Empty address returned for wallet \"${this.type}\"`);\n }\n this._address = address;\n return { address, publicKey: address };\n }\n\n async disconnect(): Promise<void> {\n try {\n await StellarWalletsKit.disconnect();\n } finally {\n this._address = null;\n }\n }\n\n async getPublicKey(): Promise<string | null> {\n if (this._address) return this._address;\n try {\n const { address } = await StellarWalletsKit.getAddress();\n this._address = address ?? null;\n return this._address;\n } catch {\n return null;\n }\n }\n\n async signTransaction(xdr: string, options?: SignTransactionOptions): Promise<SignTransactionResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const result = await StellarWalletsKit.signTransaction(xdr, {\n ...(options?.networkPassphrase !== undefined && { networkPassphrase: options.networkPassphrase }),\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedTxXdr: result.signedTxXdr };\n }\n\n async signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const result = await StellarWalletsKit.signAuthEntry(entryXdr, {\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedAuthEntry: result.signedAuthEntry };\n }\n}\n","import { type ModuleInterface, Networks, StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';\nimport { AlbedoModule } from '@creit.tech/stellar-wallets-kit/modules/albedo';\nimport { BitgetModule } from '@creit.tech/stellar-wallets-kit/modules/bitget';\nimport { CactusLinkModule } from '@creit.tech/stellar-wallets-kit/modules/cactuslink';\nimport { FordefiModule } from '@creit.tech/stellar-wallets-kit/modules/fordefi';\nimport { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';\nimport { HanaModule } from '@creit.tech/stellar-wallets-kit/modules/hana';\nimport { HotWalletModule } from '@creit.tech/stellar-wallets-kit/modules/hotwallet';\nimport { KleverModule } from '@creit.tech/stellar-wallets-kit/modules/klever';\nimport { LobstrModule } from '@creit.tech/stellar-wallets-kit/modules/lobstr';\nimport { OneKeyModule } from '@creit.tech/stellar-wallets-kit/modules/onekey';\nimport { RabetModule } from '@creit.tech/stellar-wallets-kit/modules/rabet';\nimport { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';\nimport type { WalletAdapterResolver, WalletId } from '@pollar/core';\nimport { StellarWalletsKitAdapter } from './StellarWalletsKitAdapter';\n\nexport interface StellarWalletsKitAdapterOptions {\n /**\n * Stellar network the kit will use for signing. Defaults to `Networks.TESTNET`.\n */\n network?: Networks;\n /**\n * Wallet modules the kit should drive. Defaults to every module that works\n * out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,\n * HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list\n * to add Ledger / Trezor / WalletConnect — those need extra setup (a\n * Buffer polyfill for Ledger; constructor params for the other two) so we\n * don't auto-include them.\n *\n * Import modules from their kit subpaths so the bundle stays lean:\n * ```ts\n * import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';\n * ```\n */\n modules?: ModuleInterface[];\n}\n\nlet initialised = false;\n\nfunction buildDefaultModules(): ModuleInterface[] {\n return [\n new AlbedoModule(),\n new BitgetModule(),\n new CactusLinkModule(),\n new FordefiModule(),\n new FreighterModule(),\n new HanaModule(),\n new HotWalletModule(),\n new KleverModule(),\n new LobstrModule(),\n new OneKeyModule(),\n new RabetModule(),\n new xBullModule(),\n ];\n}\n\nfunction ensureInit(options: StellarWalletsKitAdapterOptions): void {\n if (initialised) return;\n StellarWalletsKit.init({\n network: options.network ?? Networks.TESTNET,\n modules: options.modules ?? buildDefaultModules(),\n });\n initialised = true;\n}\n\n/**\n * Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass\n * the result to `PollarClientConfig.walletAdapter` so Pollar can use any of\n * the kit's modules without `@pollar/core` having to depend on the kit.\n *\n * @example\n * ```ts\n * import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';\n * import { Networks } from '@creit.tech/stellar-wallets-kit';\n *\n * const client = new PollarClient({\n * apiKey: '…',\n * walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),\n * });\n * ```\n */\nexport function stellarWalletsKit(options: StellarWalletsKitAdapterOptions = {}): WalletAdapterResolver {\n return (id: WalletId) => {\n ensureInit(options);\n return new StellarWalletsKitAdapter(id);\n };\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { StellarWalletsKit, Networks } from '@creit.tech/stellar-wallets-kit';
|
|
2
|
+
import { AlbedoModule } from '@creit.tech/stellar-wallets-kit/modules/albedo';
|
|
3
|
+
import { BitgetModule } from '@creit.tech/stellar-wallets-kit/modules/bitget';
|
|
4
|
+
import { CactusLinkModule } from '@creit.tech/stellar-wallets-kit/modules/cactuslink';
|
|
5
|
+
import { FordefiModule } from '@creit.tech/stellar-wallets-kit/modules/fordefi';
|
|
6
|
+
import { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';
|
|
7
|
+
import { HanaModule } from '@creit.tech/stellar-wallets-kit/modules/hana';
|
|
8
|
+
import { HotWalletModule } from '@creit.tech/stellar-wallets-kit/modules/hotwallet';
|
|
9
|
+
import { KleverModule } from '@creit.tech/stellar-wallets-kit/modules/klever';
|
|
10
|
+
import { LobstrModule } from '@creit.tech/stellar-wallets-kit/modules/lobstr';
|
|
11
|
+
import { OneKeyModule } from '@creit.tech/stellar-wallets-kit/modules/onekey';
|
|
12
|
+
import { RabetModule } from '@creit.tech/stellar-wallets-kit/modules/rabet';
|
|
13
|
+
import { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';
|
|
14
|
+
|
|
15
|
+
// src/StellarWalletsKitAdapter.ts
|
|
16
|
+
var StellarWalletsKitAdapter = class {
|
|
17
|
+
constructor(walletId) {
|
|
18
|
+
this._address = null;
|
|
19
|
+
this.type = walletId;
|
|
20
|
+
}
|
|
21
|
+
async isAvailable() {
|
|
22
|
+
try {
|
|
23
|
+
StellarWalletsKit.setWallet(String(this.type));
|
|
24
|
+
return true;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async connect() {
|
|
30
|
+
StellarWalletsKit.setWallet(String(this.type));
|
|
31
|
+
const { address } = await StellarWalletsKit.fetchAddress();
|
|
32
|
+
if (!address) {
|
|
33
|
+
throw new Error(`[StellarWalletsKit] Empty address returned for wallet "${this.type}"`);
|
|
34
|
+
}
|
|
35
|
+
this._address = address;
|
|
36
|
+
return { address, publicKey: address };
|
|
37
|
+
}
|
|
38
|
+
async disconnect() {
|
|
39
|
+
try {
|
|
40
|
+
await StellarWalletsKit.disconnect();
|
|
41
|
+
} finally {
|
|
42
|
+
this._address = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async getPublicKey() {
|
|
46
|
+
if (this._address) return this._address;
|
|
47
|
+
try {
|
|
48
|
+
const { address } = await StellarWalletsKit.getAddress();
|
|
49
|
+
this._address = address ?? null;
|
|
50
|
+
return this._address;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async signTransaction(xdr, options) {
|
|
56
|
+
StellarWalletsKit.setWallet(String(this.type));
|
|
57
|
+
const result = await StellarWalletsKit.signTransaction(xdr, {
|
|
58
|
+
...options?.networkPassphrase !== void 0 && { networkPassphrase: options.networkPassphrase },
|
|
59
|
+
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
60
|
+
});
|
|
61
|
+
return { signedTxXdr: result.signedTxXdr };
|
|
62
|
+
}
|
|
63
|
+
async signAuthEntry(entryXdr, options) {
|
|
64
|
+
StellarWalletsKit.setWallet(String(this.type));
|
|
65
|
+
const result = await StellarWalletsKit.signAuthEntry(entryXdr, {
|
|
66
|
+
...options?.accountToSign !== void 0 && { address: options.accountToSign }
|
|
67
|
+
});
|
|
68
|
+
return { signedAuthEntry: result.signedAuthEntry };
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var initialised = false;
|
|
72
|
+
function buildDefaultModules() {
|
|
73
|
+
return [
|
|
74
|
+
new AlbedoModule(),
|
|
75
|
+
new BitgetModule(),
|
|
76
|
+
new CactusLinkModule(),
|
|
77
|
+
new FordefiModule(),
|
|
78
|
+
new FreighterModule(),
|
|
79
|
+
new HanaModule(),
|
|
80
|
+
new HotWalletModule(),
|
|
81
|
+
new KleverModule(),
|
|
82
|
+
new LobstrModule(),
|
|
83
|
+
new OneKeyModule(),
|
|
84
|
+
new RabetModule(),
|
|
85
|
+
new xBullModule()
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
function ensureInit(options) {
|
|
89
|
+
if (initialised) return;
|
|
90
|
+
StellarWalletsKit.init({
|
|
91
|
+
network: options.network ?? Networks.TESTNET,
|
|
92
|
+
modules: options.modules ?? buildDefaultModules()
|
|
93
|
+
});
|
|
94
|
+
initialised = true;
|
|
95
|
+
}
|
|
96
|
+
function stellarWalletsKit(options = {}) {
|
|
97
|
+
return (id) => {
|
|
98
|
+
ensureInit(options);
|
|
99
|
+
return new StellarWalletsKitAdapter(id);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { StellarWalletsKitAdapter, stellarWalletsKit };
|
|
104
|
+
//# sourceMappingURL=index.mjs.map
|
|
105
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/StellarWalletsKitAdapter.ts","../src/factory.ts"],"names":["StellarWalletsKit"],"mappings":";;;;;;;;;;;;;;;AAiBO,IAAM,2BAAN,MAAwD;AAAA,EAI7D,YAAY,QAAA,EAAoB;AAFhC,IAAA,IAAA,CAAQ,QAAA,GAA0B,IAAA;AAGhC,IAAA,IAAA,CAAK,IAAA,GAAO,QAAA;AAAA,EACd;AAAA,EAEA,MAAM,WAAA,GAAgC;AACpC,IAAA,IAAI;AACF,MAAA,iBAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAK7C,MAAA,OAAO,IAAA;AAAA,IACT,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,OAAA,GAA0C;AAC9C,IAAA,iBAAA,CAAkB,SAAA,CAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAC,CAAA;AAC7C,IAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAM,kBAAkB,YAAA,EAAa;AACzD,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,uDAAA,EAA0D,IAAA,CAAK,IAAI,CAAA,CAAA,CAAG,CAAA;AAAA,IACxF;AACA,IAAA,IAAA,CAAK,QAAA,GA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ConnectWalletResponse,\n SignAuthEntryOptions,\n SignAuthEntryResponse,\n SignTransactionOptions,\n SignTransactionResponse,\n WalletAdapter,\n WalletId,\n} from '@pollar/core';\n\n/**\n * Wraps Stellar Wallets Kit so it satisfies the `@pollar/core` `WalletAdapter`\n * contract. The kit is a global singleton — `setWallet` is called before every\n * operation so the correct module handles the request, which lets a single\n * `StellarWalletsKit.init(...)` cover many wallet modules.\n */\nexport class StellarWalletsKitAdapter implements WalletAdapter {\n readonly type: WalletId;\n private _address: string | null = null;\n\n constructor(walletId: WalletId) {\n this.type = walletId;\n }\n\n async isAvailable(): Promise<boolean> {\n try {\n StellarWalletsKit.setWallet(String(this.type));\n // The kit doesn't expose a top-level `isAvailable`; once the module is\n // selected, attempting an address fetch is the cheapest probe — but it\n // can pop UI on some wallets. Return true and let `connect()` surface\n // the real availability error if any.\n return true;\n } catch {\n return false;\n }\n }\n\n async connect(): Promise<ConnectWalletResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const { address } = await StellarWalletsKit.fetchAddress();\n if (!address) {\n throw new Error(`[StellarWalletsKit] Empty address returned for wallet \"${this.type}\"`);\n }\n this._address = address;\n return { address, publicKey: address };\n }\n\n async disconnect(): Promise<void> {\n try {\n await StellarWalletsKit.disconnect();\n } finally {\n this._address = null;\n }\n }\n\n async getPublicKey(): Promise<string | null> {\n if (this._address) return this._address;\n try {\n const { address } = await StellarWalletsKit.getAddress();\n this._address = address ?? null;\n return this._address;\n } catch {\n return null;\n }\n }\n\n async signTransaction(xdr: string, options?: SignTransactionOptions): Promise<SignTransactionResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const result = await StellarWalletsKit.signTransaction(xdr, {\n ...(options?.networkPassphrase !== undefined && { networkPassphrase: options.networkPassphrase }),\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedTxXdr: result.signedTxXdr };\n }\n\n async signAuthEntry(entryXdr: string, options?: SignAuthEntryOptions): Promise<SignAuthEntryResponse> {\n StellarWalletsKit.setWallet(String(this.type));\n const result = await StellarWalletsKit.signAuthEntry(entryXdr, {\n ...(options?.accountToSign !== undefined && { address: options.accountToSign }),\n });\n return { signedAuthEntry: result.signedAuthEntry };\n }\n}\n","import { type ModuleInterface, Networks, StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';\nimport { AlbedoModule } from '@creit.tech/stellar-wallets-kit/modules/albedo';\nimport { BitgetModule } from '@creit.tech/stellar-wallets-kit/modules/bitget';\nimport { CactusLinkModule } from '@creit.tech/stellar-wallets-kit/modules/cactuslink';\nimport { FordefiModule } from '@creit.tech/stellar-wallets-kit/modules/fordefi';\nimport { FreighterModule } from '@creit.tech/stellar-wallets-kit/modules/freighter';\nimport { HanaModule } from '@creit.tech/stellar-wallets-kit/modules/hana';\nimport { HotWalletModule } from '@creit.tech/stellar-wallets-kit/modules/hotwallet';\nimport { KleverModule } from '@creit.tech/stellar-wallets-kit/modules/klever';\nimport { LobstrModule } from '@creit.tech/stellar-wallets-kit/modules/lobstr';\nimport { OneKeyModule } from '@creit.tech/stellar-wallets-kit/modules/onekey';\nimport { RabetModule } from '@creit.tech/stellar-wallets-kit/modules/rabet';\nimport { xBullModule } from '@creit.tech/stellar-wallets-kit/modules/xbull';\nimport type { WalletAdapterResolver, WalletId } from '@pollar/core';\nimport { StellarWalletsKitAdapter } from './StellarWalletsKitAdapter';\n\nexport interface StellarWalletsKitAdapterOptions {\n /**\n * Stellar network the kit will use for signing. Defaults to `Networks.TESTNET`.\n */\n network?: Networks;\n /**\n * Wallet modules the kit should drive. Defaults to every module that works\n * out of the box (Albedo, Bitget, CactusLink, Fordefi, Freighter, Hana,\n * HotWallet, Klever, Lobstr, OneKey, Rabet, xBull). Pass an explicit list\n * to add Ledger / Trezor / WalletConnect — those need extra setup (a\n * Buffer polyfill for Ledger; constructor params for the other two) so we\n * don't auto-include them.\n *\n * Import modules from their kit subpaths so the bundle stays lean:\n * ```ts\n * import { WalletConnectModule } from '@creit.tech/stellar-wallets-kit/modules/wallet-connect';\n * ```\n */\n modules?: ModuleInterface[];\n}\n\nlet initialised = false;\n\nfunction buildDefaultModules(): ModuleInterface[] {\n return [\n new AlbedoModule(),\n new BitgetModule(),\n new CactusLinkModule(),\n new FordefiModule(),\n new FreighterModule(),\n new HanaModule(),\n new HotWalletModule(),\n new KleverModule(),\n new LobstrModule(),\n new OneKeyModule(),\n new RabetModule(),\n new xBullModule(),\n ];\n}\n\nfunction ensureInit(options: StellarWalletsKitAdapterOptions): void {\n if (initialised) return;\n StellarWalletsKit.init({\n network: options.network ?? Networks.TESTNET,\n modules: options.modules ?? buildDefaultModules(),\n });\n initialised = true;\n}\n\n/**\n * Build a {@link WalletAdapterResolver} backed by Stellar Wallets Kit. Pass\n * the result to `PollarClientConfig.walletAdapter` so Pollar can use any of\n * the kit's modules without `@pollar/core` having to depend on the kit.\n *\n * @example\n * ```ts\n * import { stellarWalletsKit } from '@pollar/stellar-wallets-kit-adapter';\n * import { Networks } from '@creit.tech/stellar-wallets-kit';\n *\n * const client = new PollarClient({\n * apiKey: '…',\n * walletAdapter: stellarWalletsKit({ network: Networks.PUBLIC }),\n * });\n * ```\n */\nexport function stellarWalletsKit(options: StellarWalletsKitAdapterOptions = {}): WalletAdapterResolver {\n return (id: WalletId) => {\n ensureInit(options);\n return new StellarWalletsKitAdapter(id);\n };\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pollar/stellar-wallets-kit-adapter",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"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
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch",
|
|
27
|
+
"lint": "tsc --noEmit && eslint src",
|
|
28
|
+
"clean": "rm -rf dist"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@creit.tech/stellar-wallets-kit": "^2.0.0",
|
|
35
|
+
"@pollar/core": "*"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@pollar/core": "*"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@creit.tech/stellar-wallets-kit": "^2.2.0",
|
|
42
|
+
"@eslint/js": "^9.39.4",
|
|
43
|
+
"eslint": "^9.39.4",
|
|
44
|
+
"tsup": "^8.3.0",
|
|
45
|
+
"typescript": "^5.7.0",
|
|
46
|
+
"typescript-eslint": "^8.58.1"
|
|
47
|
+
}
|
|
48
|
+
}
|