@phantom/browser-sdk 1.0.0-beta.9 → 1.0.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 +341 -94
- package/dist/index.d.ts +96 -68
- package/dist/index.js +2755 -678
- package/dist/index.mjs +2750 -683
- package/package.json +15 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EmbeddedProviderConfig,
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
1
|
+
import { EmbeddedProviderConfig, EmbeddedProviderAuthType, ConnectResult as ConnectResult$1, WalletAddress, EmbeddedProviderEvent, EventCallback } from '@phantom/embedded-provider-core';
|
|
2
|
+
export { ConnectErrorEventData, ConnectEventData, ConnectStartEventData, DisconnectEventData, EmbeddedProviderEvent, EmbeddedProviderEventMap, EventCallback, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
|
|
3
|
+
import { IEthereumChain, ISolanaChain } from '@phantom/chain-interfaces';
|
|
4
4
|
export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chain-interfaces';
|
|
5
5
|
import { AddressType } from '@phantom/client';
|
|
6
6
|
export { AddressType } from '@phantom/client';
|
|
@@ -52,51 +52,97 @@ declare const DebugCategory: {
|
|
|
52
52
|
readonly SESSION: "Session";
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
interface PhantomAppLoginOptions {
|
|
56
|
+
publicKey: string;
|
|
57
|
+
appId: string;
|
|
58
|
+
sessionId: string;
|
|
59
|
+
}
|
|
60
|
+
interface PhantomAppLoginResult {
|
|
61
|
+
walletId: string;
|
|
62
|
+
organizationId: string;
|
|
63
|
+
accountDerivationIndex?: number;
|
|
64
|
+
expiresInMs?: number;
|
|
65
|
+
authUserId?: string;
|
|
66
|
+
}
|
|
67
|
+
interface PhantomApp {
|
|
68
|
+
login(options: PhantomAppLoginOptions): Promise<PhantomAppLoginResult>;
|
|
69
|
+
features(): Promise<{
|
|
70
|
+
features: string[];
|
|
71
|
+
}>;
|
|
72
|
+
getUser(): Promise<{
|
|
73
|
+
authUserId?: string;
|
|
74
|
+
} | undefined>;
|
|
75
|
+
}
|
|
55
76
|
declare global {
|
|
56
77
|
interface Window {
|
|
57
78
|
phantom?: {
|
|
58
79
|
solana?: unknown;
|
|
59
80
|
ethereum?: unknown;
|
|
60
|
-
|
|
81
|
+
app?: PhantomApp;
|
|
82
|
+
} | undefined;
|
|
61
83
|
}
|
|
62
84
|
}
|
|
85
|
+
|
|
63
86
|
interface InjectedProviderConfig {
|
|
64
87
|
addressTypes: AddressType[];
|
|
65
88
|
}
|
|
66
89
|
|
|
90
|
+
type InjectedWalletId = string;
|
|
91
|
+
interface WalletProviders {
|
|
92
|
+
/** EIP-6963 Ethereum provider (window.ethereum-like) */
|
|
93
|
+
ethereum?: IEthereumChain;
|
|
94
|
+
/** Wallet Standard Solana wallet object */
|
|
95
|
+
solana?: ISolanaChain;
|
|
96
|
+
}
|
|
97
|
+
interface InjectedWalletInfo {
|
|
98
|
+
id: InjectedWalletId;
|
|
99
|
+
name: string;
|
|
100
|
+
icon?: string;
|
|
101
|
+
addressTypes: AddressType[];
|
|
102
|
+
providers?: WalletProviders;
|
|
103
|
+
/** Reverse DNS identifier from EIP-6963 (for potential future matching with Wallet Standard) */
|
|
104
|
+
rdns?: string;
|
|
105
|
+
discovery?: "standard" | "eip6963" | "phantom";
|
|
106
|
+
}
|
|
107
|
+
|
|
67
108
|
interface DebugConfig {
|
|
68
109
|
enabled?: boolean;
|
|
69
110
|
level?: DebugLevel;
|
|
70
111
|
callback?: DebugCallback;
|
|
71
112
|
}
|
|
72
|
-
type BrowserSDKConfig = Prettify<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
type Prettify<T> = {
|
|
76
|
-
[K in keyof T]: T[K];
|
|
77
|
-
} & {};
|
|
78
|
-
interface ExtendedEmbeddedProviderConfig extends Omit<EmbeddedProviderConfig, "authOptions" | "apiBaseUrl" | "embeddedWalletType"> {
|
|
79
|
-
providerType: "embedded";
|
|
113
|
+
type BrowserSDKConfig = Prettify<Omit<EmbeddedProviderConfig, "authOptions" | "apiBaseUrl" | "embeddedWalletType" | "appId"> & InjectedProviderConfig & {
|
|
114
|
+
providers: AuthProviderType[];
|
|
115
|
+
appId?: string;
|
|
80
116
|
apiBaseUrl?: string;
|
|
81
117
|
embeddedWalletType?: "app-wallet" | "user-wallet";
|
|
82
118
|
authOptions?: {
|
|
83
119
|
authUrl?: string;
|
|
84
120
|
redirectUrl?: string;
|
|
85
121
|
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
122
|
+
}>;
|
|
123
|
+
type Prettify<T> = {
|
|
124
|
+
[K in keyof T]: T[K];
|
|
125
|
+
} & {};
|
|
126
|
+
type AuthProviderType = EmbeddedProviderAuthType | "injected" | "deeplink";
|
|
127
|
+
type AuthOptions = {
|
|
128
|
+
provider: AuthProviderType;
|
|
129
|
+
walletId?: string;
|
|
130
|
+
customAuthData?: Record<string, any>;
|
|
131
|
+
};
|
|
93
132
|
|
|
133
|
+
type ConnectResultWalletInfo = Omit<InjectedWalletInfo, "providers">;
|
|
134
|
+
type ConnectResult = Omit<ConnectResult$1, "authProvider"> & {
|
|
135
|
+
authProvider?: AuthProviderType | undefined;
|
|
136
|
+
walletId?: string | undefined;
|
|
137
|
+
wallet?: ConnectResultWalletInfo | undefined;
|
|
138
|
+
};
|
|
94
139
|
interface Provider {
|
|
95
|
-
connect(authOptions
|
|
140
|
+
connect(authOptions: AuthOptions): Promise<ConnectResult>;
|
|
96
141
|
disconnect(): Promise<void>;
|
|
97
142
|
getAddresses(): WalletAddress[];
|
|
98
143
|
isConnected(): boolean;
|
|
99
144
|
autoConnect(): Promise<void>;
|
|
145
|
+
getEnabledAddressTypes(): AddressType[];
|
|
100
146
|
solana: ISolanaChain;
|
|
101
147
|
ethereum: IEthereumChain;
|
|
102
148
|
}
|
|
@@ -105,26 +151,14 @@ interface ProviderPreference {
|
|
|
105
151
|
type: "injected" | "embedded";
|
|
106
152
|
embeddedWalletType?: "app-wallet" | "user-wallet";
|
|
107
153
|
}
|
|
108
|
-
interface SwitchProviderOptions {
|
|
109
|
-
embeddedWalletType?: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
110
|
-
}
|
|
111
154
|
|
|
112
|
-
/**
|
|
113
|
-
* Browser SDK with chain-specific API
|
|
114
|
-
*
|
|
115
|
-
* Usage:
|
|
116
|
-
* ```typescript
|
|
117
|
-
* const sdk = new BrowserSDK({ providerType: 'embedded', appId: 'your-app-id' });
|
|
118
|
-
* await sdk.connect();
|
|
119
|
-
*
|
|
120
|
-
* // Chain-specific operations
|
|
121
|
-
* await sdk.solana.signMessage(message);
|
|
122
|
-
* await sdk.ethereum.signPersonalMessage(message, address);
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
155
|
declare class BrowserSDK {
|
|
126
156
|
private providerManager;
|
|
157
|
+
private walletRegistry;
|
|
158
|
+
private config;
|
|
159
|
+
isLoading: boolean;
|
|
127
160
|
constructor(config: BrowserSDKConfig);
|
|
161
|
+
discoverWallets(): Promise<void>;
|
|
128
162
|
/**
|
|
129
163
|
* Access Solana chain operations
|
|
130
164
|
*/
|
|
@@ -136,15 +170,11 @@ declare class BrowserSDK {
|
|
|
136
170
|
/**
|
|
137
171
|
* Connect to the wallet
|
|
138
172
|
*/
|
|
139
|
-
connect(options
|
|
173
|
+
connect(options: AuthOptions): Promise<ConnectResult>;
|
|
140
174
|
/**
|
|
141
175
|
* Disconnect from the wallet
|
|
142
176
|
*/
|
|
143
177
|
disconnect(): Promise<void>;
|
|
144
|
-
/**
|
|
145
|
-
* Switch between provider types (injected vs embedded)
|
|
146
|
-
*/
|
|
147
|
-
switchProvider(type: "injected" | "embedded", options?: SwitchProviderOptions): Promise<void>;
|
|
148
178
|
/**
|
|
149
179
|
* Check if the SDK is connected to a wallet
|
|
150
180
|
*/
|
|
@@ -158,13 +188,12 @@ declare class BrowserSDK {
|
|
|
158
188
|
*/
|
|
159
189
|
getCurrentProviderInfo(): ProviderPreference | null;
|
|
160
190
|
/**
|
|
161
|
-
* Get
|
|
191
|
+
* Get enabled address types for the current provider
|
|
192
|
+
* - For embedded provider: returns config.addressTypes
|
|
193
|
+
* - For Phantom injected: returns config.addressTypes
|
|
194
|
+
* - For discovered wallets: returns the wallet's addressTypes from registry
|
|
162
195
|
*/
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Check if Phantom extension is installed
|
|
166
|
-
*/
|
|
167
|
-
static isPhantomInstalled(timeoutMs?: number): Promise<boolean>;
|
|
196
|
+
getEnabledAddressTypes(): AddressType[];
|
|
168
197
|
/**
|
|
169
198
|
* Add event listener for provider events (connect, connect_start, connect_error, disconnect, error)
|
|
170
199
|
* Works with both embedded and injected providers
|
|
@@ -178,32 +207,13 @@ declare class BrowserSDK {
|
|
|
178
207
|
/**
|
|
179
208
|
* Attempt auto-connection using existing session
|
|
180
209
|
* Should be called after setting up event listeners
|
|
181
|
-
*
|
|
210
|
+
* Tries embedded provider first, then injected provider as fallback
|
|
182
211
|
*/
|
|
183
212
|
autoConnect(): Promise<void>;
|
|
184
|
-
/**
|
|
185
|
-
* Debug configuration methods
|
|
186
|
-
* These allow dynamic debug configuration without SDK reinstantiation
|
|
187
|
-
*/
|
|
188
|
-
/**
|
|
189
|
-
* Enable debug logging
|
|
190
|
-
*/
|
|
191
213
|
enableDebug(): void;
|
|
192
|
-
/**
|
|
193
|
-
* Disable debug logging
|
|
194
|
-
*/
|
|
195
214
|
disableDebug(): void;
|
|
196
|
-
/**
|
|
197
|
-
* Set debug level
|
|
198
|
-
*/
|
|
199
215
|
setDebugLevel(level: DebugLevel): void;
|
|
200
|
-
/**
|
|
201
|
-
* Set debug callback function
|
|
202
|
-
*/
|
|
203
216
|
setDebugCallback(callback: DebugCallback): void;
|
|
204
|
-
/**
|
|
205
|
-
* Configure debug settings all at once
|
|
206
|
-
*/
|
|
207
217
|
configureDebug(config: {
|
|
208
218
|
enabled?: boolean;
|
|
209
219
|
level?: DebugLevel;
|
|
@@ -229,6 +239,7 @@ declare class BrowserSDK {
|
|
|
229
239
|
* Only available for injected providers
|
|
230
240
|
*/
|
|
231
241
|
getSupportedAutoConfirmChains(): Promise<AutoConfirmSupportedChainsResult>;
|
|
242
|
+
getDiscoveredWallets(): InjectedWalletInfo[];
|
|
232
243
|
}
|
|
233
244
|
|
|
234
245
|
/**
|
|
@@ -289,4 +300,21 @@ declare function getDeeplinkToPhantom(ref?: string): string;
|
|
|
289
300
|
*/
|
|
290
301
|
declare function waitForPhantomExtension(timeoutMs?: number): Promise<boolean>;
|
|
291
302
|
|
|
292
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Check if Phantom Login is available
|
|
305
|
+
*
|
|
306
|
+
* This function checks if:
|
|
307
|
+
* 1. The Phantom extension is installed
|
|
308
|
+
* 2. The extension supports the phantom_login feature
|
|
309
|
+
*
|
|
310
|
+
* @param timeoutMs - Maximum time to wait for extension in milliseconds (default: 3000)
|
|
311
|
+
* @returns Promise<boolean> - true if Phantom Login is available, false otherwise
|
|
312
|
+
*
|
|
313
|
+
* Usage:
|
|
314
|
+
* ```typescript
|
|
315
|
+
* const isAvailable = await isPhantomLoginAvailable();
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
declare function isPhantomLoginAvailable(timeoutMs?: number): Promise<boolean>;
|
|
319
|
+
|
|
320
|
+
export { AuthOptions, AuthProviderType, BrowserInfo, BrowserSDK, BrowserSDKConfig, ConnectResult, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, InjectedWalletId, InjectedWalletInfo, Provider, debug, detectBrowser, getBrowserDisplayName, getDeeplinkToPhantom, getPlatformName, isMobileDevice, isPhantomLoginAvailable, parseBrowserFromUserAgent, waitForPhantomExtension };
|