@phantom/browser-sdk 1.0.0-beta.1 → 1.0.0-beta.10
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 +37 -60
- package/dist/index.d.ts +48 -15
- package/dist/index.js +283 -88
- package/dist/index.mjs +280 -85
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -44,8 +44,7 @@ import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
|
44
44
|
const sdk = new BrowserSDK({
|
|
45
45
|
providerType: "embedded",
|
|
46
46
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
47
|
-
|
|
48
|
-
appId: "your-app-id",
|
|
47
|
+
appId: "your-app-id", // Get your app ID from phantom.com/portal
|
|
49
48
|
});
|
|
50
49
|
|
|
51
50
|
const { addresses } = await sdk.connect();
|
|
@@ -190,48 +189,29 @@ Creates a non-custodial wallet embedded in your application. Requires API config
|
|
|
190
189
|
const sdk = new BrowserSDK({
|
|
191
190
|
providerType: "embedded",
|
|
192
191
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
193
|
-
|
|
194
|
-
appId: "your-app-id",
|
|
195
|
-
embeddedWalletType: "app-wallet", // or 'user-wallet'
|
|
192
|
+
appId: "your-app-id", // Get your app ID from phantom.com/portal
|
|
196
193
|
authOptions: {
|
|
197
|
-
authUrl: "https://
|
|
194
|
+
authUrl: "https://connect.phantom.app/login", // optional, defaults to "https://connect.phantom.app/login"
|
|
198
195
|
redirectUrl: "https://yourapp.com/callback", // optional, defaults to current page
|
|
199
196
|
},
|
|
200
197
|
autoConnect: true, // optional, auto-connect to existing session (default: true for embedded)
|
|
201
198
|
});
|
|
202
199
|
```
|
|
203
200
|
|
|
204
|
-
### Embedded Wallet
|
|
205
|
-
|
|
206
|
-
#### App Wallet (`'app-wallet'`)
|
|
207
|
-
|
|
208
|
-
- **New wallets** created per application
|
|
209
|
-
- **Unfunded** by default - you need to fund them
|
|
210
|
-
- **Independent** from user's existing Phantom wallet
|
|
211
|
-
- **Perfect for**: Gaming, DeFi protocols, or apps that need fresh wallets
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
const sdk = new BrowserSDK({
|
|
215
|
-
providerType: "embedded",
|
|
216
|
-
embeddedWalletType: "app-wallet",
|
|
217
|
-
addressTypes: [AddressType.solana],
|
|
218
|
-
// ... other config
|
|
219
|
-
});
|
|
220
|
-
```
|
|
201
|
+
### Embedded Wallet Type
|
|
221
202
|
|
|
222
203
|
#### User Wallet (`'user-wallet'`)
|
|
223
204
|
|
|
224
205
|
- **Uses Phantom authentication** - user logs in with existing Phantom account
|
|
225
206
|
- **Potentially funded** - brings in user's existing wallet balance
|
|
226
207
|
- **Connected** to user's Phantom ecosystem
|
|
227
|
-
- **Perfect for**:
|
|
208
|
+
- **Perfect for**: All embedded wallet use cases
|
|
228
209
|
|
|
229
210
|
```typescript
|
|
230
211
|
const sdk = new BrowserSDK({
|
|
231
212
|
providerType: "embedded",
|
|
232
|
-
|
|
213
|
+
appId: "your-app-id",
|
|
233
214
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
234
|
-
// ... other config
|
|
235
215
|
});
|
|
236
216
|
```
|
|
237
217
|
|
|
@@ -242,28 +222,6 @@ const sdk = new BrowserSDK({
|
|
|
242
222
|
| `AddressType.solana` | Solana Mainnet, Devnet, Testnet |
|
|
243
223
|
| `AddressType.ethereum` | Ethereum, Polygon, Arbitrum, and more |
|
|
244
224
|
|
|
245
|
-
### Solana Provider Configuration
|
|
246
|
-
|
|
247
|
-
When using `AddressType.solana`, you can choose between two Solana libraries:
|
|
248
|
-
|
|
249
|
-
```typescript
|
|
250
|
-
const sdk = new BrowserSDK({
|
|
251
|
-
providerType: "embedded",
|
|
252
|
-
addressTypes: [AddressType.solana],
|
|
253
|
-
solanaProvider: "web3js", // or 'kit'
|
|
254
|
-
// ... other config
|
|
255
|
-
});
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
**Provider Options:**
|
|
259
|
-
|
|
260
|
-
- `'web3js'` (default) - Uses `@solana/web3.js` library
|
|
261
|
-
- `'kit'` - Uses `@solana/kit` library (modern, TypeScript-first)
|
|
262
|
-
|
|
263
|
-
**When to use each:**
|
|
264
|
-
|
|
265
|
-
- **@solana/web3.js**: Better ecosystem compatibility, wider community support
|
|
266
|
-
- **@solana/kit**: Better TypeScript support, modern architecture, smaller bundle size
|
|
267
225
|
|
|
268
226
|
### Auto-Connect Feature
|
|
269
227
|
|
|
@@ -272,8 +230,8 @@ The SDK can automatically reconnect to existing sessions when instantiated, prov
|
|
|
272
230
|
```typescript
|
|
273
231
|
const sdk = new BrowserSDK({
|
|
274
232
|
providerType: "embedded",
|
|
233
|
+
appId: "your-app-id",
|
|
275
234
|
addressTypes: [AddressType.solana],
|
|
276
|
-
// ... other config
|
|
277
235
|
autoConnect: true, // Default: true for embedded, false for injected
|
|
278
236
|
});
|
|
279
237
|
|
|
@@ -295,8 +253,8 @@ if (sdk.isConnected()) {
|
|
|
295
253
|
```typescript
|
|
296
254
|
const sdk = new BrowserSDK({
|
|
297
255
|
providerType: "embedded",
|
|
256
|
+
appId: "your-app-id",
|
|
298
257
|
addressTypes: [AddressType.solana],
|
|
299
|
-
// ... other config
|
|
300
258
|
autoConnect: false, // Disable auto-connect
|
|
301
259
|
});
|
|
302
260
|
|
|
@@ -320,15 +278,16 @@ interface BrowserSDKConfig {
|
|
|
320
278
|
addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
|
|
321
279
|
|
|
322
280
|
// Required for embedded provider only
|
|
323
|
-
|
|
324
|
-
|
|
281
|
+
appId?: string; // Your app ID from phantom.com/portal (required for embedded provider)
|
|
282
|
+
|
|
283
|
+
// Optional configuration
|
|
284
|
+
apiBaseUrl?: string; // Phantom API base URL (optional, has default)
|
|
325
285
|
authOptions?: {
|
|
326
|
-
authUrl?: string; // Custom auth URL (
|
|
327
|
-
redirectUrl?: string; // Custom redirect URL after authentication
|
|
286
|
+
authUrl?: string; // Custom auth URL (optional, defaults to "https://connect.phantom.app/login")
|
|
287
|
+
redirectUrl?: string; // Custom redirect URL after authentication (optional)
|
|
328
288
|
};
|
|
329
|
-
embeddedWalletType?: "
|
|
330
|
-
|
|
331
|
-
autoConnect?: boolean; // Enable auto-connect to existing sessions (default: true)
|
|
289
|
+
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet", currently the only supported type)
|
|
290
|
+
autoConnect?: boolean; // Enable auto-connect to existing sessions (optional, defaults to true for embedded)
|
|
332
291
|
}
|
|
333
292
|
```
|
|
334
293
|
|
|
@@ -463,6 +422,12 @@ const balance = await sdk.ethereum.request({
|
|
|
463
422
|
method: "eth_getBalance",
|
|
464
423
|
params: [address, "latest"],
|
|
465
424
|
});
|
|
425
|
+
|
|
426
|
+
// Sign transaction via RPC (alternative to signTransaction method)
|
|
427
|
+
const signedTx = await sdk.ethereum.request({
|
|
428
|
+
method: "eth_signTransaction",
|
|
429
|
+
params: [{ to: "0x...", value: "0x...", gas: "0x..." }],
|
|
430
|
+
});
|
|
466
431
|
```
|
|
467
432
|
|
|
468
433
|
#### signPersonalMessage(message, address)
|
|
@@ -511,6 +476,20 @@ const signature = await sdk.ethereum.signTypedData(typedData, address);
|
|
|
511
476
|
// Returns: { signature: string, rawSignature: string }
|
|
512
477
|
```
|
|
513
478
|
|
|
479
|
+
#### signTransaction(transaction)
|
|
480
|
+
|
|
481
|
+
Sign an Ethereum transaction without sending it.
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
const signedTx = await sdk.ethereum.signTransaction({
|
|
485
|
+
to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
|
|
486
|
+
value: "1000000000000000000", // 1 ETH in wei
|
|
487
|
+
gas: "21000",
|
|
488
|
+
gasPrice: "20000000000", // 20 gwei
|
|
489
|
+
});
|
|
490
|
+
// Returns: string (hex-encoded signed transaction)
|
|
491
|
+
```
|
|
492
|
+
|
|
514
493
|
#### sendTransaction(transaction)
|
|
515
494
|
|
|
516
495
|
Send an Ethereum transaction.
|
|
@@ -728,7 +707,7 @@ import { BrowserSDK, DebugLevel } from "@phantom/browser-sdk";
|
|
|
728
707
|
|
|
729
708
|
const sdk = new BrowserSDK({
|
|
730
709
|
providerType: "embedded",
|
|
731
|
-
|
|
710
|
+
appId: "your-app-id",
|
|
732
711
|
});
|
|
733
712
|
|
|
734
713
|
// Store debug messages
|
|
@@ -795,7 +774,6 @@ import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
|
795
774
|
const sdk = new BrowserSDK({
|
|
796
775
|
providerType: "injected",
|
|
797
776
|
addressTypes: [AddressType.solana],
|
|
798
|
-
solanaProvider: "web3js",
|
|
799
777
|
});
|
|
800
778
|
|
|
801
779
|
await sdk.connect();
|
|
@@ -849,7 +827,6 @@ import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
|
849
827
|
const sdk = new BrowserSDK({
|
|
850
828
|
providerType: "injected",
|
|
851
829
|
addressTypes: [AddressType.solana],
|
|
852
|
-
solanaProvider: "kit",
|
|
853
830
|
});
|
|
854
831
|
|
|
855
832
|
await sdk.connect();
|
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
2
|
export { AuthOptions, ConnectResult, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
|
|
3
|
-
import { ISolanaChain, IEthereumChain } from '@phantom/
|
|
4
|
-
export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/
|
|
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,43 @@ declare const DebugCategory: {
|
|
|
52
52
|
readonly SESSION: "Session";
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
declare global {
|
|
56
|
+
interface Window {
|
|
57
|
+
phantom?: {
|
|
58
|
+
solana?: unknown;
|
|
59
|
+
ethereum?: unknown;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
interface InjectedProviderConfig {
|
|
64
|
+
addressTypes: AddressType[];
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
interface DebugConfig {
|
|
56
68
|
enabled?: boolean;
|
|
57
69
|
level?: DebugLevel;
|
|
58
70
|
callback?: DebugCallback;
|
|
59
71
|
}
|
|
60
|
-
|
|
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>);
|
|
72
|
+
type BrowserSDKConfig = Prettify<(ExtendedEmbeddedProviderConfig | ExtendedInjectedProviderConfig) & {
|
|
66
73
|
autoConnect?: boolean;
|
|
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";
|
|
80
|
+
apiBaseUrl?: string;
|
|
81
|
+
embeddedWalletType?: "app-wallet" | "user-wallet";
|
|
82
|
+
authOptions?: {
|
|
83
|
+
authUrl?: string;
|
|
84
|
+
redirectUrl?: string;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
interface ExtendedInjectedProviderConfig extends InjectedProviderConfig {
|
|
88
|
+
providerType: "injected";
|
|
89
|
+
appId?: never;
|
|
90
|
+
authOptions?: never;
|
|
91
|
+
embeddedWalletType?: never;
|
|
67
92
|
}
|
|
68
93
|
|
|
69
94
|
interface Provider {
|
|
@@ -71,6 +96,7 @@ interface Provider {
|
|
|
71
96
|
disconnect(): Promise<void>;
|
|
72
97
|
getAddresses(): WalletAddress[];
|
|
73
98
|
isConnected(): boolean;
|
|
99
|
+
autoConnect(): Promise<void>;
|
|
74
100
|
solana: ISolanaChain;
|
|
75
101
|
ethereum: IEthereumChain;
|
|
76
102
|
}
|
|
@@ -205,18 +231,13 @@ declare class BrowserSDK {
|
|
|
205
231
|
getSupportedAutoConfirmChains(): Promise<AutoConfirmSupportedChainsResult>;
|
|
206
232
|
}
|
|
207
233
|
|
|
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
234
|
/**
|
|
215
235
|
* Browser detection utility to identify browser name and version
|
|
216
236
|
*/
|
|
217
237
|
interface BrowserInfo {
|
|
218
238
|
name: string;
|
|
219
239
|
version: string;
|
|
240
|
+
userAgent: string;
|
|
220
241
|
}
|
|
221
242
|
/**
|
|
222
243
|
* Parse browser information from a user agent string
|
|
@@ -237,6 +258,18 @@ declare function getPlatformName(): string;
|
|
|
237
258
|
* Format: "Chrome 120.0" or "Firefox 119.0"
|
|
238
259
|
*/
|
|
239
260
|
declare function getBrowserDisplayName(): string;
|
|
261
|
+
/**
|
|
262
|
+
* Detect if the current device is a mobile device
|
|
263
|
+
* Checks user agent for mobile indicators and screen size
|
|
264
|
+
*/
|
|
265
|
+
declare function isMobileDevice(): boolean;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Generates a deeplink URL to open the current page in Phantom mobile app
|
|
269
|
+
* @param ref Optional referrer parameter
|
|
270
|
+
* @returns Phantom mobile app deeplink URL
|
|
271
|
+
*/
|
|
272
|
+
declare function getDeeplinkToPhantom(ref?: string): string;
|
|
240
273
|
|
|
241
274
|
/**
|
|
242
275
|
* Wait for Phantom extension to be available with retry logic
|
|
@@ -256,4 +289,4 @@ declare function getBrowserDisplayName(): string;
|
|
|
256
289
|
*/
|
|
257
290
|
declare function waitForPhantomExtension(timeoutMs?: number): Promise<boolean>;
|
|
258
291
|
|
|
259
|
-
export { BrowserInfo, BrowserSDK, BrowserSDKConfig,
|
|
292
|
+
export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getDeeplinkToPhantom, getPlatformName, isMobileDevice, parseBrowserFromUserAgent, waitForPhantomExtension };
|