@phantom/browser-sdk 1.0.0-beta.0 → 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 +110 -122
- package/dist/index.d.ts +67 -16
- package/dist/index.js +538 -163
- package/dist/index.mjs +541 -167
- package/package.json +11 -9
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
|
-
organizationId: "your-org-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();
|
|
@@ -107,7 +106,7 @@ const result = await sdk.connect({
|
|
|
107
106
|
},
|
|
108
107
|
});
|
|
109
108
|
|
|
110
|
-
// Apple authentication (skips provider selection)
|
|
109
|
+
// Apple authentication (skips provider selection)
|
|
111
110
|
const result = await sdk.connect({
|
|
112
111
|
authOptions: {
|
|
113
112
|
provider: "apple",
|
|
@@ -132,7 +131,7 @@ const signedTx = await sdk.solana.signTransaction(transaction);
|
|
|
132
131
|
const result = await sdk.solana.signAndSendTransaction(transaction);
|
|
133
132
|
|
|
134
133
|
// Network switching
|
|
135
|
-
await sdk.solana.switchNetwork(
|
|
134
|
+
await sdk.solana.switchNetwork("devnet");
|
|
136
135
|
|
|
137
136
|
// Utilities
|
|
138
137
|
const publicKey = await sdk.solana.getPublicKey();
|
|
@@ -143,8 +142,8 @@ const isConnected = sdk.solana.isConnected();
|
|
|
143
142
|
|
|
144
143
|
```typescript
|
|
145
144
|
// EIP-1193 requests
|
|
146
|
-
const accounts = await sdk.ethereum.request({ method:
|
|
147
|
-
const chainId = await sdk.ethereum.request({ method:
|
|
145
|
+
const accounts = await sdk.ethereum.request({ method: "eth_accounts" });
|
|
146
|
+
const chainId = await sdk.ethereum.request({ method: "eth_chainId" });
|
|
148
147
|
|
|
149
148
|
// Message signing
|
|
150
149
|
const signature = await sdk.ethereum.signPersonalMessage(message, address);
|
|
@@ -190,82 +189,39 @@ 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
|
-
organizationId: "your-org-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
|
-
appName: "My DApp", // optional, for branding
|
|
201
|
-
appLogo: "https://myapp.com/logo.png", // optional, for branding
|
|
202
197
|
autoConnect: true, // optional, auto-connect to existing session (default: true for embedded)
|
|
203
198
|
});
|
|
204
199
|
```
|
|
205
200
|
|
|
206
|
-
### Embedded Wallet
|
|
207
|
-
|
|
208
|
-
#### App Wallet (`'app-wallet'`)
|
|
209
|
-
|
|
210
|
-
- **New wallets** created per application
|
|
211
|
-
- **Unfunded** by default - you need to fund them
|
|
212
|
-
- **Independent** from user's existing Phantom wallet
|
|
213
|
-
- **Perfect for**: Gaming, DeFi protocols, or apps that need fresh wallets
|
|
214
|
-
|
|
215
|
-
```typescript
|
|
216
|
-
const sdk = new BrowserSDK({
|
|
217
|
-
providerType: "embedded",
|
|
218
|
-
embeddedWalletType: "app-wallet",
|
|
219
|
-
addressTypes: [AddressType.solana],
|
|
220
|
-
// ... other config
|
|
221
|
-
});
|
|
222
|
-
```
|
|
201
|
+
### Embedded Wallet Type
|
|
223
202
|
|
|
224
203
|
#### User Wallet (`'user-wallet'`)
|
|
225
204
|
|
|
226
205
|
- **Uses Phantom authentication** - user logs in with existing Phantom account
|
|
227
206
|
- **Potentially funded** - brings in user's existing wallet balance
|
|
228
207
|
- **Connected** to user's Phantom ecosystem
|
|
229
|
-
- **Perfect for**:
|
|
208
|
+
- **Perfect for**: All embedded wallet use cases
|
|
230
209
|
|
|
231
210
|
```typescript
|
|
232
211
|
const sdk = new BrowserSDK({
|
|
233
212
|
providerType: "embedded",
|
|
234
|
-
|
|
213
|
+
appId: "your-app-id",
|
|
235
214
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
236
|
-
// ... other config
|
|
237
215
|
});
|
|
238
216
|
```
|
|
239
217
|
|
|
240
218
|
### Available AddressTypes
|
|
241
219
|
|
|
242
|
-
| AddressType
|
|
243
|
-
|
|
|
244
|
-
| `AddressType.solana`
|
|
245
|
-
| `AddressType.ethereum`
|
|
246
|
-
|
|
247
|
-
### Solana Provider Configuration
|
|
248
|
-
|
|
249
|
-
When using `AddressType.solana`, you can choose between two Solana libraries:
|
|
250
|
-
|
|
251
|
-
```typescript
|
|
252
|
-
const sdk = new BrowserSDK({
|
|
253
|
-
providerType: "embedded",
|
|
254
|
-
addressTypes: [AddressType.solana],
|
|
255
|
-
solanaProvider: "web3js", // or 'kit'
|
|
256
|
-
// ... other config
|
|
257
|
-
});
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
**Provider Options:**
|
|
261
|
-
|
|
262
|
-
- `'web3js'` (default) - Uses `@solana/web3.js` library
|
|
263
|
-
- `'kit'` - Uses `@solana/kit` library (modern, TypeScript-first)
|
|
264
|
-
|
|
265
|
-
**When to use each:**
|
|
220
|
+
| AddressType | Supported Chains |
|
|
221
|
+
| ---------------------- | ------------------------------------- |
|
|
222
|
+
| `AddressType.solana` | Solana Mainnet, Devnet, Testnet |
|
|
223
|
+
| `AddressType.ethereum` | Ethereum, Polygon, Arbitrum, and more |
|
|
266
224
|
|
|
267
|
-
- **@solana/web3.js**: Better ecosystem compatibility, wider community support
|
|
268
|
-
- **@solana/kit**: Better TypeScript support, modern architecture, smaller bundle size
|
|
269
225
|
|
|
270
226
|
### Auto-Connect Feature
|
|
271
227
|
|
|
@@ -274,8 +230,8 @@ The SDK can automatically reconnect to existing sessions when instantiated, prov
|
|
|
274
230
|
```typescript
|
|
275
231
|
const sdk = new BrowserSDK({
|
|
276
232
|
providerType: "embedded",
|
|
233
|
+
appId: "your-app-id",
|
|
277
234
|
addressTypes: [AddressType.solana],
|
|
278
|
-
// ... other config
|
|
279
235
|
autoConnect: true, // Default: true for embedded, false for injected
|
|
280
236
|
});
|
|
281
237
|
|
|
@@ -297,8 +253,8 @@ if (sdk.isConnected()) {
|
|
|
297
253
|
```typescript
|
|
298
254
|
const sdk = new BrowserSDK({
|
|
299
255
|
providerType: "embedded",
|
|
256
|
+
appId: "your-app-id",
|
|
300
257
|
addressTypes: [AddressType.solana],
|
|
301
|
-
// ... other config
|
|
302
258
|
autoConnect: false, // Disable auto-connect
|
|
303
259
|
});
|
|
304
260
|
|
|
@@ -319,20 +275,35 @@ new BrowserSDK(config: BrowserSDKConfig)
|
|
|
319
275
|
```typescript
|
|
320
276
|
interface BrowserSDKConfig {
|
|
321
277
|
providerType: "injected" | "embedded";
|
|
322
|
-
appName?: string; // Optional app name for branding
|
|
323
|
-
appLogo?: string; // Optional app logo URL for branding
|
|
324
278
|
addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
|
|
325
279
|
|
|
326
280
|
// Required for embedded provider only
|
|
327
|
-
|
|
328
|
-
|
|
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)
|
|
329
285
|
authOptions?: {
|
|
330
|
-
authUrl?: string; // Custom auth URL (
|
|
331
|
-
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)
|
|
332
288
|
};
|
|
333
|
-
embeddedWalletType?: "
|
|
334
|
-
|
|
335
|
-
|
|
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)
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Extension Detection
|
|
295
|
+
|
|
296
|
+
For injected provider usage, you can check if the Phantom extension is installed:
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
import { waitForPhantomExtension } from "@phantom/browser-sdk";
|
|
300
|
+
|
|
301
|
+
const isAvailable = await waitForPhantomExtension(5000);
|
|
302
|
+
|
|
303
|
+
if (isAvailable) {
|
|
304
|
+
console.log("Phantom extension is available!");
|
|
305
|
+
} else {
|
|
306
|
+
console.log("Phantom extension not found");
|
|
336
307
|
}
|
|
337
308
|
```
|
|
338
309
|
|
|
@@ -416,8 +387,8 @@ const result = await sdk.solana.signAndSendTransaction(transaction);
|
|
|
416
387
|
Switch between Solana networks.
|
|
417
388
|
|
|
418
389
|
```typescript
|
|
419
|
-
await sdk.solana.switchNetwork(
|
|
420
|
-
await sdk.solana.switchNetwork(
|
|
390
|
+
await sdk.solana.switchNetwork("mainnet");
|
|
391
|
+
await sdk.solana.switchNetwork("devnet");
|
|
421
392
|
```
|
|
422
393
|
|
|
423
394
|
#### getPublicKey()
|
|
@@ -445,11 +416,17 @@ const connected = sdk.solana.isConnected();
|
|
|
445
416
|
Make an EIP-1193 compatible request.
|
|
446
417
|
|
|
447
418
|
```typescript
|
|
448
|
-
const accounts = await sdk.ethereum.request({ method:
|
|
449
|
-
const chainId = await sdk.ethereum.request({ method:
|
|
450
|
-
const balance = await sdk.ethereum.request({
|
|
451
|
-
method:
|
|
452
|
-
params: [address,
|
|
419
|
+
const accounts = await sdk.ethereum.request({ method: "eth_accounts" });
|
|
420
|
+
const chainId = await sdk.ethereum.request({ method: "eth_chainId" });
|
|
421
|
+
const balance = await sdk.ethereum.request({
|
|
422
|
+
method: "eth_getBalance",
|
|
423
|
+
params: [address, "latest"],
|
|
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..." }],
|
|
453
430
|
});
|
|
454
431
|
```
|
|
455
432
|
|
|
@@ -473,32 +450,46 @@ const typedData = {
|
|
|
473
450
|
{ name: "name", type: "string" },
|
|
474
451
|
{ name: "version", type: "string" },
|
|
475
452
|
{ name: "chainId", type: "uint256" },
|
|
476
|
-
{ name: "verifyingContract", type: "address" }
|
|
453
|
+
{ name: "verifyingContract", type: "address" },
|
|
477
454
|
],
|
|
478
455
|
Mail: [
|
|
479
456
|
{ name: "from", type: "string" },
|
|
480
457
|
{ name: "to", type: "string" },
|
|
481
|
-
{ name: "contents", type: "string" }
|
|
482
|
-
]
|
|
458
|
+
{ name: "contents", type: "string" },
|
|
459
|
+
],
|
|
483
460
|
},
|
|
484
461
|
primaryType: "Mail",
|
|
485
462
|
domain: {
|
|
486
463
|
name: "Ether Mail",
|
|
487
464
|
version: "1",
|
|
488
465
|
chainId: 1,
|
|
489
|
-
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
|
|
466
|
+
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
|
|
490
467
|
},
|
|
491
468
|
message: {
|
|
492
469
|
from: "Alice",
|
|
493
470
|
to: "Bob",
|
|
494
|
-
contents: "Hello!"
|
|
495
|
-
}
|
|
471
|
+
contents: "Hello!",
|
|
472
|
+
},
|
|
496
473
|
};
|
|
497
474
|
|
|
498
475
|
const signature = await sdk.ethereum.signTypedData(typedData, address);
|
|
499
476
|
// Returns: { signature: string, rawSignature: string }
|
|
500
477
|
```
|
|
501
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
|
+
|
|
502
493
|
#### sendTransaction(transaction)
|
|
503
494
|
|
|
504
495
|
Send an Ethereum transaction.
|
|
@@ -518,8 +509,8 @@ const result = await sdk.ethereum.sendTransaction({
|
|
|
518
509
|
Switch to a different Ethereum chain.
|
|
519
510
|
|
|
520
511
|
```typescript
|
|
521
|
-
await sdk.ethereum.switchChain(1);
|
|
522
|
-
await sdk.ethereum.switchChain(137);
|
|
512
|
+
await sdk.ethereum.switchChain(1); // Ethereum mainnet
|
|
513
|
+
await sdk.ethereum.switchChain(137); // Polygon
|
|
523
514
|
await sdk.ethereum.switchChain(42161); // Arbitrum One
|
|
524
515
|
```
|
|
525
516
|
|
|
@@ -571,10 +562,10 @@ import { NetworkId } from "@phantom/browser-sdk";
|
|
|
571
562
|
|
|
572
563
|
// Enable auto-confirm for specific chains
|
|
573
564
|
const result = await sdk.enableAutoConfirm({
|
|
574
|
-
chains: [NetworkId.SOLANA_MAINNET, NetworkId.ETHEREUM_MAINNET]
|
|
565
|
+
chains: [NetworkId.SOLANA_MAINNET, NetworkId.ETHEREUM_MAINNET],
|
|
575
566
|
});
|
|
576
567
|
|
|
577
|
-
// Enable auto-confirm for all supported chains
|
|
568
|
+
// Enable auto-confirm for all supported chains
|
|
578
569
|
const result = await sdk.enableAutoConfirm();
|
|
579
570
|
|
|
580
571
|
console.log("Auto-confirm enabled:", result.enabled);
|
|
@@ -619,29 +610,29 @@ console.log("Supported chains:", supportedChains.chains);
|
|
|
619
610
|
import { NetworkId } from "@phantom/browser-sdk";
|
|
620
611
|
|
|
621
612
|
// Solana networks
|
|
622
|
-
NetworkId.SOLANA_MAINNET
|
|
623
|
-
NetworkId.SOLANA_DEVNET
|
|
624
|
-
NetworkId.SOLANA_TESTNET
|
|
613
|
+
NetworkId.SOLANA_MAINNET; // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
614
|
+
NetworkId.SOLANA_DEVNET; // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
615
|
+
NetworkId.SOLANA_TESTNET; // "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
|
|
625
616
|
|
|
626
617
|
// Ethereum networks
|
|
627
|
-
NetworkId.ETHEREUM_MAINNET // "eip155:1"
|
|
628
|
-
NetworkId.ETHEREUM_SEPOLIA // "eip155:11155111"
|
|
618
|
+
NetworkId.ETHEREUM_MAINNET; // "eip155:1"
|
|
619
|
+
NetworkId.ETHEREUM_SEPOLIA; // "eip155:11155111"
|
|
629
620
|
|
|
630
|
-
// Polygon networks
|
|
631
|
-
NetworkId.POLYGON_MAINNET
|
|
632
|
-
NetworkId.POLYGON_AMOY
|
|
621
|
+
// Polygon networks
|
|
622
|
+
NetworkId.POLYGON_MAINNET; // "eip155:137"
|
|
623
|
+
NetworkId.POLYGON_AMOY; // "eip155:80002"
|
|
633
624
|
|
|
634
625
|
// Arbitrum networks
|
|
635
|
-
NetworkId.ARBITRUM_ONE
|
|
636
|
-
NetworkId.ARBITRUM_SEPOLIA // "eip155:421614"
|
|
626
|
+
NetworkId.ARBITRUM_ONE; // "eip155:42161"
|
|
627
|
+
NetworkId.ARBITRUM_SEPOLIA; // "eip155:421614"
|
|
637
628
|
|
|
638
629
|
// Optimism networks
|
|
639
|
-
NetworkId.OPTIMISM_MAINNET // "eip155:10"
|
|
640
|
-
NetworkId.OPTIMISM_GOERLI
|
|
630
|
+
NetworkId.OPTIMISM_MAINNET; // "eip155:10"
|
|
631
|
+
NetworkId.OPTIMISM_GOERLI; // "eip155:420"
|
|
641
632
|
|
|
642
633
|
// Base networks
|
|
643
|
-
NetworkId.BASE_MAINNET
|
|
644
|
-
NetworkId.BASE_SEPOLIA
|
|
634
|
+
NetworkId.BASE_MAINNET; // "eip155:8453"
|
|
635
|
+
NetworkId.BASE_SEPOLIA; // "eip155:84532"
|
|
645
636
|
```
|
|
646
637
|
|
|
647
638
|
**Important Notes:**
|
|
@@ -661,14 +652,14 @@ The BrowserSDK provides dynamic debug configuration that can be changed at runti
|
|
|
661
652
|
// Enable debug logging
|
|
662
653
|
sdk.enableDebug();
|
|
663
654
|
|
|
664
|
-
// Disable debug logging
|
|
655
|
+
// Disable debug logging
|
|
665
656
|
sdk.disableDebug();
|
|
666
657
|
|
|
667
658
|
// Set debug level
|
|
668
659
|
sdk.setDebugLevel(DebugLevel.INFO);
|
|
669
660
|
|
|
670
661
|
// Set debug callback function
|
|
671
|
-
sdk.setDebugCallback(
|
|
662
|
+
sdk.setDebugCallback(message => {
|
|
672
663
|
console.log(`[${message.category}] ${message.message}`, message.data);
|
|
673
664
|
});
|
|
674
665
|
|
|
@@ -676,10 +667,10 @@ sdk.setDebugCallback((message) => {
|
|
|
676
667
|
sdk.configureDebug({
|
|
677
668
|
enabled: true,
|
|
678
669
|
level: DebugLevel.DEBUG,
|
|
679
|
-
callback:
|
|
670
|
+
callback: message => {
|
|
680
671
|
// Handle debug messages
|
|
681
672
|
console.log(`[${message.level}] ${message.category}: ${message.message}`);
|
|
682
|
-
}
|
|
673
|
+
},
|
|
683
674
|
});
|
|
684
675
|
```
|
|
685
676
|
|
|
@@ -689,10 +680,10 @@ sdk.configureDebug({
|
|
|
689
680
|
import { DebugLevel } from "@phantom/browser-sdk";
|
|
690
681
|
|
|
691
682
|
// Available debug levels (in order of verbosity)
|
|
692
|
-
DebugLevel.ERROR
|
|
693
|
-
DebugLevel.WARN
|
|
694
|
-
DebugLevel.INFO
|
|
695
|
-
DebugLevel.DEBUG
|
|
683
|
+
DebugLevel.ERROR; // 0 - Only error messages
|
|
684
|
+
DebugLevel.WARN; // 1 - Warning and error messages
|
|
685
|
+
DebugLevel.INFO; // 2 - Info, warning, and error messages
|
|
686
|
+
DebugLevel.DEBUG; // 3 - All debug messages (most verbose)
|
|
696
687
|
```
|
|
697
688
|
|
|
698
689
|
### Debug Message Structure
|
|
@@ -701,11 +692,11 @@ Debug callbacks receive a `DebugMessage` object:
|
|
|
701
692
|
|
|
702
693
|
```typescript
|
|
703
694
|
interface DebugMessage {
|
|
704
|
-
timestamp: number;
|
|
705
|
-
level: DebugLevel;
|
|
706
|
-
category: string;
|
|
707
|
-
message: string;
|
|
708
|
-
data?: any;
|
|
695
|
+
timestamp: number; // Unix timestamp
|
|
696
|
+
level: DebugLevel; // Message level
|
|
697
|
+
category: string; // Component category (e.g., "BrowserSDK", "ProviderManager")
|
|
698
|
+
message: string; // Debug message text
|
|
699
|
+
data?: any; // Additional debug data (optional)
|
|
709
700
|
}
|
|
710
701
|
```
|
|
711
702
|
|
|
@@ -716,7 +707,7 @@ import { BrowserSDK, DebugLevel } from "@phantom/browser-sdk";
|
|
|
716
707
|
|
|
717
708
|
const sdk = new BrowserSDK({
|
|
718
709
|
providerType: "embedded",
|
|
719
|
-
|
|
710
|
+
appId: "your-app-id",
|
|
720
711
|
});
|
|
721
712
|
|
|
722
713
|
// Store debug messages
|
|
@@ -726,17 +717,17 @@ const debugMessages: DebugMessage[] = [];
|
|
|
726
717
|
sdk.configureDebug({
|
|
727
718
|
enabled: true,
|
|
728
719
|
level: DebugLevel.INFO,
|
|
729
|
-
callback:
|
|
720
|
+
callback: message => {
|
|
730
721
|
debugMessages.push(message);
|
|
731
|
-
|
|
722
|
+
|
|
732
723
|
// Keep only last 100 messages
|
|
733
724
|
if (debugMessages.length > 100) {
|
|
734
725
|
debugMessages.shift();
|
|
735
726
|
}
|
|
736
|
-
|
|
727
|
+
|
|
737
728
|
// Update UI
|
|
738
729
|
updateDebugConsole();
|
|
739
|
-
}
|
|
730
|
+
},
|
|
740
731
|
});
|
|
741
732
|
|
|
742
733
|
// Dynamic debug level changing
|
|
@@ -783,7 +774,6 @@ import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
|
783
774
|
const sdk = new BrowserSDK({
|
|
784
775
|
providerType: "injected",
|
|
785
776
|
addressTypes: [AddressType.solana],
|
|
786
|
-
solanaProvider: "web3js",
|
|
787
777
|
});
|
|
788
778
|
|
|
789
779
|
await sdk.connect();
|
|
@@ -835,9 +825,8 @@ import {
|
|
|
835
825
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
836
826
|
|
|
837
827
|
const sdk = new BrowserSDK({
|
|
838
|
-
providerType: "injected",
|
|
828
|
+
providerType: "injected",
|
|
839
829
|
addressTypes: [AddressType.solana],
|
|
840
|
-
solanaProvider: "kit",
|
|
841
830
|
});
|
|
842
831
|
|
|
843
832
|
await sdk.connect();
|
|
@@ -926,4 +915,3 @@ const result = await sdk.ethereum.sendTransaction({
|
|
|
926
915
|
maxPriorityFeePerGas: parseGwei("2").toString(),
|
|
927
916
|
});
|
|
928
917
|
```
|
|
929
|
-
|
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
|
-
organizationId?: 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
|
}
|
|
@@ -138,7 +164,7 @@ declare class BrowserSDK {
|
|
|
138
164
|
/**
|
|
139
165
|
* Check if Phantom extension is installed
|
|
140
166
|
*/
|
|
141
|
-
static isPhantomInstalled(): boolean
|
|
167
|
+
static isPhantomInstalled(timeoutMs?: number): Promise<boolean>;
|
|
142
168
|
/**
|
|
143
169
|
* Add event listener for provider events (connect, connect_start, connect_error, disconnect, error)
|
|
144
170
|
* Works with both embedded and injected providers
|
|
@@ -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,5 +258,35 @@ 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;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Wait for Phantom extension to be available with retry logic
|
|
276
|
+
*
|
|
277
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 3000)
|
|
278
|
+
* @returns Promise<boolean> - true if Phantom extension is available, false if timeout reached
|
|
279
|
+
*
|
|
280
|
+
* Usage:
|
|
281
|
+
* ```typescript
|
|
282
|
+
* const isAvailable = await waitForPhantomExtension(5000);
|
|
283
|
+
* if (isAvailable) {
|
|
284
|
+
* console.log("Phantom extension is available!");
|
|
285
|
+
* } else {
|
|
286
|
+
* console.log("Phantom extension not found or timed out");
|
|
287
|
+
* }
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
declare function waitForPhantomExtension(timeoutMs?: number): Promise<boolean>;
|
|
240
291
|
|
|
241
|
-
export { BrowserInfo, BrowserSDK, BrowserSDKConfig,
|
|
292
|
+
export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getDeeplinkToPhantom, getPlatformName, isMobileDevice, parseBrowserFromUserAgent, waitForPhantomExtension };
|