@phantom/browser-sdk 1.0.0-beta.22 → 1.0.0-beta.24
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 +78 -0
- package/dist/index.d.ts +31 -27
- package/dist/index.js +2165 -457
- package/dist/index.mjs +2156 -460
- package/package.json +15 -10
package/README.md
CHANGED
|
@@ -620,6 +620,84 @@ Attempt auto-connection using existing session. Should be called after setting u
|
|
|
620
620
|
await sdk.autoConnect();
|
|
621
621
|
```
|
|
622
622
|
|
|
623
|
+
### Wallet Discovery Methods
|
|
624
|
+
|
|
625
|
+
The SDK can discover multiple injected wallets using Wallet Standard for Solana and EIP-6963 for Ethereum. This allows users to choose from any installed wallet that supports the configured address types.
|
|
626
|
+
|
|
627
|
+
#### discoverWallets()
|
|
628
|
+
|
|
629
|
+
Asynchronously discover all available injected wallets that support the configured address types. This method uses Wallet Standard (`navigator.wallets.getWallets()`) for Solana wallets and EIP-6963 events for Ethereum wallets.
|
|
630
|
+
|
|
631
|
+
**Returns:** `Promise<InjectedWalletInfo[]>` - Array of discovered wallet information
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
// Discover wallets asynchronously
|
|
635
|
+
const wallets = await sdk.discoverWallets();
|
|
636
|
+
|
|
637
|
+
console.log("Discovered wallets:", wallets);
|
|
638
|
+
// Example output:
|
|
639
|
+
// [
|
|
640
|
+
// {
|
|
641
|
+
// id: "backpack",
|
|
642
|
+
// name: "Backpack",
|
|
643
|
+
// icon: "https://backpack.app/icon.png",
|
|
644
|
+
// addressTypes: [AddressType.solana],
|
|
645
|
+
// chains: ["solana:mainnet", "solana:devnet"]
|
|
646
|
+
// },
|
|
647
|
+
// {
|
|
648
|
+
// id: "metamask-io",
|
|
649
|
+
// name: "MetaMask",
|
|
650
|
+
// icon: "https://metamask.io/icon.png",
|
|
651
|
+
// addressTypes: [AddressType.ethereum],
|
|
652
|
+
// chains: ["eip155:1", "eip155:5", "eip155:11155111"]
|
|
653
|
+
// }
|
|
654
|
+
// ]
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
**Behavior:**
|
|
658
|
+
|
|
659
|
+
- Automatically filters wallets based on `config.addressTypes`
|
|
660
|
+
- If `addressTypes` is undefined or empty, discovers all wallets regardless of chain support
|
|
661
|
+
- Registers discovered wallets in the internal registry for later retrieval
|
|
662
|
+
- Discovery typically takes ~400ms (EIP-6963 timeout)
|
|
663
|
+
- Returns empty array on error (errors are logged but not thrown)
|
|
664
|
+
|
|
665
|
+
**Note:** Discovery happens automatically when the SDK is instantiated. This method is useful for manually triggering discovery or refreshing the wallet list.
|
|
666
|
+
|
|
667
|
+
#### getDiscoveredWallets()
|
|
668
|
+
|
|
669
|
+
Get all currently discovered wallets from the internal registry. This is a synchronous method that returns wallets that have already been discovered.
|
|
670
|
+
|
|
671
|
+
**Returns:** `InjectedWalletInfo[]` - Array of discovered wallet information
|
|
672
|
+
|
|
673
|
+
```typescript
|
|
674
|
+
// Get already discovered wallets (synchronous)
|
|
675
|
+
const wallets = sdk.getDiscoveredWallets();
|
|
676
|
+
|
|
677
|
+
console.log("Available wallets:", wallets);
|
|
678
|
+
// Returns wallets that match the configured addressTypes
|
|
679
|
+
// Also includes Phantom if available and matches addressTypes
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
**Behavior:**
|
|
683
|
+
|
|
684
|
+
- Returns wallets from the internal registry that match `config.addressTypes`
|
|
685
|
+
- Includes Phantom wallet if `window.phantom` is available and matches configured address types
|
|
686
|
+
- Returns empty array if no wallets are discovered or if an error occurs
|
|
687
|
+
- This is a synchronous read operation - it does not trigger new discovery
|
|
688
|
+
|
|
689
|
+
**Wallet Information Structure:**
|
|
690
|
+
|
|
691
|
+
```typescript
|
|
692
|
+
interface InjectedWalletInfo {
|
|
693
|
+
id: string; // Unique wallet identifier (e.g., "backpack", "metamask-io")
|
|
694
|
+
name: string; // Human-readable wallet name (e.g., "Backpack", "MetaMask")
|
|
695
|
+
icon?: string; // Wallet icon URL (optional)
|
|
696
|
+
addressTypes: AddressType[]; // Supported address types (e.g., [AddressType.solana])
|
|
697
|
+
chains?: string[]; // Supported chains in CAIP-2 format (e.g., ["solana:mainnet"])
|
|
698
|
+
}
|
|
699
|
+
```
|
|
700
|
+
|
|
623
701
|
### Event Handlers
|
|
624
702
|
|
|
625
703
|
The SDK provides typed event handlers that allow you to listen for connection state changes. This is especially useful for `autoConnect()` flows where you need to track the connection result.
|
package/dist/index.d.ts
CHANGED
|
@@ -108,10 +108,12 @@ type Prettify<T> = {
|
|
|
108
108
|
type AuthProviderType = EmbeddedProviderAuthType | "injected";
|
|
109
109
|
type AuthOptions = {
|
|
110
110
|
provider: AuthProviderType;
|
|
111
|
+
walletId?: string;
|
|
111
112
|
customAuthData?: Record<string, any>;
|
|
112
113
|
};
|
|
113
114
|
type ConnectResult = Omit<ConnectResult$1, "authProvider"> & {
|
|
114
115
|
authProvider?: AuthProviderType | undefined;
|
|
116
|
+
walletId?: string | undefined;
|
|
115
117
|
};
|
|
116
118
|
|
|
117
119
|
interface Provider {
|
|
@@ -120,6 +122,7 @@ interface Provider {
|
|
|
120
122
|
getAddresses(): WalletAddress[];
|
|
121
123
|
isConnected(): boolean;
|
|
122
124
|
autoConnect(): Promise<void>;
|
|
125
|
+
getEnabledAddressTypes(): AddressType[];
|
|
123
126
|
solana: ISolanaChain;
|
|
124
127
|
ethereum: IEthereumChain;
|
|
125
128
|
}
|
|
@@ -129,9 +132,30 @@ interface ProviderPreference {
|
|
|
129
132
|
embeddedWalletType?: "app-wallet" | "user-wallet";
|
|
130
133
|
}
|
|
131
134
|
|
|
135
|
+
type InjectedWalletId = string;
|
|
136
|
+
interface WalletProviders {
|
|
137
|
+
/** EIP-6963 Ethereum provider (window.ethereum-like) */
|
|
138
|
+
ethereum?: IEthereumChain;
|
|
139
|
+
/** Wallet Standard Solana wallet object */
|
|
140
|
+
solana?: ISolanaChain;
|
|
141
|
+
}
|
|
142
|
+
interface InjectedWalletInfo {
|
|
143
|
+
id: InjectedWalletId;
|
|
144
|
+
name: string;
|
|
145
|
+
icon?: string;
|
|
146
|
+
addressTypes: AddressType[];
|
|
147
|
+
providers?: WalletProviders;
|
|
148
|
+
/** Reverse DNS identifier from EIP-6963 (for potential future matching with Wallet Standard) */
|
|
149
|
+
rdns?: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
132
152
|
declare class BrowserSDK {
|
|
133
153
|
private providerManager;
|
|
154
|
+
private walletRegistry;
|
|
155
|
+
private config;
|
|
156
|
+
isLoading: boolean;
|
|
134
157
|
constructor(config: BrowserSDKConfig);
|
|
158
|
+
discoverWallets(): Promise<void>;
|
|
135
159
|
/**
|
|
136
160
|
* Access Solana chain operations
|
|
137
161
|
*/
|
|
@@ -161,9 +185,12 @@ declare class BrowserSDK {
|
|
|
161
185
|
*/
|
|
162
186
|
getCurrentProviderInfo(): ProviderPreference | null;
|
|
163
187
|
/**
|
|
164
|
-
*
|
|
188
|
+
* Get enabled address types for the current provider
|
|
189
|
+
* - For embedded provider: returns config.addressTypes
|
|
190
|
+
* - For Phantom injected: returns config.addressTypes
|
|
191
|
+
* - For discovered wallets: returns the wallet's addressTypes from registry
|
|
165
192
|
*/
|
|
166
|
-
|
|
193
|
+
getEnabledAddressTypes(): AddressType[];
|
|
167
194
|
/**
|
|
168
195
|
* Add event listener for provider events (connect, connect_start, connect_error, disconnect, error)
|
|
169
196
|
* Works with both embedded and injected providers
|
|
@@ -180,29 +207,10 @@ declare class BrowserSDK {
|
|
|
180
207
|
* Tries embedded provider first, then injected provider as fallback
|
|
181
208
|
*/
|
|
182
209
|
autoConnect(): Promise<void>;
|
|
183
|
-
/**
|
|
184
|
-
* Debug configuration methods
|
|
185
|
-
* These allow dynamic debug configuration without SDK reinstantiation
|
|
186
|
-
*/
|
|
187
|
-
/**
|
|
188
|
-
* Enable debug logging
|
|
189
|
-
*/
|
|
190
210
|
enableDebug(): void;
|
|
191
|
-
/**
|
|
192
|
-
* Disable debug logging
|
|
193
|
-
*/
|
|
194
211
|
disableDebug(): void;
|
|
195
|
-
/**
|
|
196
|
-
* Set debug level
|
|
197
|
-
*/
|
|
198
212
|
setDebugLevel(level: DebugLevel): void;
|
|
199
|
-
/**
|
|
200
|
-
* Set debug callback function
|
|
201
|
-
*/
|
|
202
213
|
setDebugCallback(callback: DebugCallback): void;
|
|
203
|
-
/**
|
|
204
|
-
* Configure debug settings all at once
|
|
205
|
-
*/
|
|
206
214
|
configureDebug(config: {
|
|
207
215
|
enabled?: boolean;
|
|
208
216
|
level?: DebugLevel;
|
|
@@ -228,6 +236,7 @@ declare class BrowserSDK {
|
|
|
228
236
|
* Only available for injected providers
|
|
229
237
|
*/
|
|
230
238
|
getSupportedAutoConfirmChains(): Promise<AutoConfirmSupportedChainsResult>;
|
|
239
|
+
getDiscoveredWallets(): InjectedWalletInfo[];
|
|
231
240
|
}
|
|
232
241
|
|
|
233
242
|
/**
|
|
@@ -301,13 +310,8 @@ declare function waitForPhantomExtension(timeoutMs?: number): Promise<boolean>;
|
|
|
301
310
|
* Usage:
|
|
302
311
|
* ```typescript
|
|
303
312
|
* const isAvailable = await isPhantomLoginAvailable();
|
|
304
|
-
* if (isAvailable) {
|
|
305
|
-
* console.log("Phantom Login is available!");
|
|
306
|
-
* } else {
|
|
307
|
-
* console.log("Phantom Login is not available");
|
|
308
|
-
* }
|
|
309
313
|
* ```
|
|
310
314
|
*/
|
|
311
315
|
declare function isPhantomLoginAvailable(timeoutMs?: number): Promise<boolean>;
|
|
312
316
|
|
|
313
|
-
export { AuthOptions, AuthProviderType, BrowserInfo, BrowserSDK, BrowserSDKConfig, ConnectResult, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getDeeplinkToPhantom, getPlatformName, isMobileDevice, isPhantomLoginAvailable, parseBrowserFromUserAgent, waitForPhantomExtension };
|
|
317
|
+
export { AuthOptions, AuthProviderType, BrowserInfo, BrowserSDK, BrowserSDKConfig, ConnectResult, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, InjectedWalletId, InjectedWalletInfo, Provider, debug, detectBrowser, getBrowserDisplayName, getDeeplinkToPhantom, getPlatformName, isMobileDevice, isPhantomLoginAvailable, parseBrowserFromUserAgent, waitForPhantomExtension };
|