@phantom/browser-sdk 1.0.0-beta.2 → 1.0.0-beta.21

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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { EmbeddedProviderConfig, AuthOptions, ConnectResult, WalletAddress, EmbeddedProviderEvent, EventCallback } from '@phantom/embedded-provider-core';
2
- export { AuthOptions, ConnectResult, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
3
- import { ISolanaChain, IEthereumChain } from '@phantom/chains';
4
- export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chains';
2
+ export { AuthOptions, ConnectErrorEventData, ConnectEventData, ConnectResult, ConnectStartEventData, DisconnectEventData, EmbeddedProviderEvent, EmbeddedProviderEventMap, EventCallback, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
3
+ import { ISolanaChain, IEthereumChain } from '@phantom/chain-interfaces';
4
+ export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chain-interfaces';
5
5
  import { AddressType } from '@phantom/client';
6
6
  export { AddressType } from '@phantom/client';
7
7
  import { AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult } from '@phantom/browser-injected-sdk/auto-confirm';
@@ -52,18 +52,69 @@ declare const DebugCategory: {
52
52
  readonly SESSION: "Session";
53
53
  };
54
54
 
55
+ /**
56
+ * Phantom extension app.login API types
57
+ */
58
+ interface PhantomAppLoginOptions {
59
+ publicKey: string;
60
+ appId: string;
61
+ sessionId: string;
62
+ }
63
+ interface PhantomAppLoginResult {
64
+ walletId: string;
65
+ organizationId: string;
66
+ accountDerivationIndex?: number;
67
+ expiresInMs?: number;
68
+ authUserId?: string;
69
+ }
70
+ interface PhantomApp {
71
+ login(options: PhantomAppLoginOptions): Promise<PhantomAppLoginResult>;
72
+ features(): Promise<{
73
+ features: string[];
74
+ }>;
75
+ getUser(): Promise<{
76
+ authUserId?: string;
77
+ } | undefined>;
78
+ }
79
+ declare global {
80
+ interface Window {
81
+ phantom?: {
82
+ solana?: unknown;
83
+ ethereum?: unknown;
84
+ app?: PhantomApp;
85
+ } | undefined;
86
+ }
87
+ }
88
+
89
+ interface InjectedProviderConfig {
90
+ addressTypes: AddressType[];
91
+ }
92
+
55
93
  interface DebugConfig {
56
94
  enabled?: boolean;
57
95
  level?: DebugLevel;
58
96
  callback?: DebugCallback;
59
97
  }
60
- interface BrowserSDKConfig extends Partial<EmbeddedProviderConfig> {
61
- providerType: "injected" | "embedded" | (string & Record<never, never>);
62
- addressTypes: [AddressType, ...AddressType[]];
63
- apiBaseUrl?: string;
64
- appId?: string;
65
- embeddedWalletType?: "app-wallet" | "user-wallet" | (string & Record<never, never>);
98
+ type BrowserSDKConfig = Prettify<(ExtendedEmbeddedProviderConfig | ExtendedInjectedProviderConfig) & {
66
99
  autoConnect?: boolean;
100
+ }>;
101
+ type Prettify<T> = {
102
+ [K in keyof T]: T[K];
103
+ } & {};
104
+ interface ExtendedEmbeddedProviderConfig extends Omit<EmbeddedProviderConfig, "authOptions" | "apiBaseUrl" | "embeddedWalletType"> {
105
+ providerType: "embedded";
106
+ apiBaseUrl?: string;
107
+ embeddedWalletType?: "app-wallet" | "user-wallet";
108
+ authOptions?: {
109
+ authUrl?: string;
110
+ redirectUrl?: string;
111
+ };
112
+ }
113
+ interface ExtendedInjectedProviderConfig extends InjectedProviderConfig {
114
+ providerType: "injected";
115
+ appId?: never;
116
+ authOptions?: never;
117
+ embeddedWalletType?: never;
67
118
  }
68
119
 
69
120
  interface Provider {
@@ -71,6 +122,7 @@ interface Provider {
71
122
  disconnect(): Promise<void>;
72
123
  getAddresses(): WalletAddress[];
73
124
  isConnected(): boolean;
125
+ autoConnect(): Promise<void>;
74
126
  solana: ISolanaChain;
75
127
  ethereum: IEthereumChain;
76
128
  }
@@ -79,9 +131,6 @@ interface ProviderPreference {
79
131
  type: "injected" | "embedded";
80
132
  embeddedWalletType?: "app-wallet" | "user-wallet";
81
133
  }
82
- interface SwitchProviderOptions {
83
- embeddedWalletType?: "app-wallet" | "user-wallet" | (string & Record<never, never>);
84
- }
85
134
 
86
135
  /**
87
136
  * Browser SDK with chain-specific API
@@ -110,15 +159,11 @@ declare class BrowserSDK {
110
159
  /**
111
160
  * Connect to the wallet
112
161
  */
113
- connect(options?: AuthOptions): Promise<ConnectResult>;
162
+ connect(options: AuthOptions): Promise<ConnectResult>;
114
163
  /**
115
164
  * Disconnect from the wallet
116
165
  */
117
166
  disconnect(): Promise<void>;
118
- /**
119
- * Switch between provider types (injected vs embedded)
120
- */
121
- switchProvider(type: "injected" | "embedded", options?: SwitchProviderOptions): Promise<void>;
122
167
  /**
123
168
  * Check if the SDK is connected to a wallet
124
169
  */
@@ -131,10 +176,6 @@ declare class BrowserSDK {
131
176
  * Get information about the current provider
132
177
  */
133
178
  getCurrentProviderInfo(): ProviderPreference | null;
134
- /**
135
- * Get the wallet ID (for embedded wallets)
136
- */
137
- getWalletId(): string | null;
138
179
  /**
139
180
  * Check if Phantom extension is installed
140
181
  */
@@ -152,7 +193,7 @@ declare class BrowserSDK {
152
193
  /**
153
194
  * Attempt auto-connection using existing session
154
195
  * Should be called after setting up event listeners
155
- * Only works with embedded providers
196
+ * Tries embedded provider first, then injected provider as fallback
156
197
  */
157
198
  autoConnect(): Promise<void>;
158
199
  /**
@@ -205,18 +246,13 @@ declare class BrowserSDK {
205
246
  getSupportedAutoConfirmChains(): Promise<AutoConfirmSupportedChainsResult>;
206
247
  }
207
248
 
208
- /**
209
- * Constants used throughout the browser SDK
210
- */
211
- declare const DEFAULT_AUTH_URL = "https://connect.phantom.app";
212
- declare const DEFAULT_WALLET_API_URL = "https://api.phantom.app/v1/wallets";
213
-
214
249
  /**
215
250
  * Browser detection utility to identify browser name and version
216
251
  */
217
252
  interface BrowserInfo {
218
253
  name: string;
219
254
  version: string;
255
+ userAgent: string;
220
256
  }
221
257
  /**
222
258
  * Parse browser information from a user agent string
@@ -237,6 +273,18 @@ declare function getPlatformName(): string;
237
273
  * Format: "Chrome 120.0" or "Firefox 119.0"
238
274
  */
239
275
  declare function getBrowserDisplayName(): string;
276
+ /**
277
+ * Detect if the current device is a mobile device
278
+ * Checks user agent for mobile indicators and screen size
279
+ */
280
+ declare function isMobileDevice(): boolean;
281
+
282
+ /**
283
+ * Generates a deeplink URL to open the current page in Phantom mobile app
284
+ * @param ref Optional referrer parameter
285
+ * @returns Phantom mobile app deeplink URL
286
+ */
287
+ declare function getDeeplinkToPhantom(ref?: string): string;
240
288
 
241
289
  /**
242
290
  * Wait for Phantom extension to be available with retry logic
@@ -256,4 +304,26 @@ declare function getBrowserDisplayName(): string;
256
304
  */
257
305
  declare function waitForPhantomExtension(timeoutMs?: number): Promise<boolean>;
258
306
 
259
- export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DEFAULT_AUTH_URL, DEFAULT_WALLET_API_URL, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getPlatformName, parseBrowserFromUserAgent, waitForPhantomExtension };
307
+ /**
308
+ * Check if Phantom Login is available
309
+ *
310
+ * This function checks if:
311
+ * 1. The Phantom extension is installed
312
+ * 2. The extension supports the phantom_login feature
313
+ *
314
+ * @param timeoutMs - Maximum time to wait for extension in milliseconds (default: 3000)
315
+ * @returns Promise<boolean> - true if Phantom Login is available, false otherwise
316
+ *
317
+ * Usage:
318
+ * ```typescript
319
+ * const isAvailable = await isPhantomLoginAvailable();
320
+ * if (isAvailable) {
321
+ * console.log("Phantom Login is available!");
322
+ * } else {
323
+ * console.log("Phantom Login is not available");
324
+ * }
325
+ * ```
326
+ */
327
+ declare function isPhantomLoginAvailable(timeoutMs?: number): Promise<boolean>;
328
+
329
+ export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getDeeplinkToPhantom, getPlatformName, isMobileDevice, isPhantomLoginAvailable, parseBrowserFromUserAgent, waitForPhantomExtension };