@phantom/browser-sdk 1.0.0-beta.20 → 1.0.0-beta.22
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 +121 -105
- package/dist/index.d.ts +19 -35
- package/dist/index.js +121 -59
- package/dist/index.mjs +123 -59
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
|
15
15
|
|
|
16
16
|
// Connect to Phantom browser extension
|
|
17
17
|
const sdk = new BrowserSDK({
|
|
18
|
-
|
|
18
|
+
providers: ["injected"], // Only allow browser extension
|
|
19
19
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -35,14 +35,14 @@ const solanaResult = await sdk.solana.signAndSendTransaction(mySolanaTransaction
|
|
|
35
35
|
const ethResult = await sdk.ethereum.sendTransaction(myEthTransaction);
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
### Embedded Provider
|
|
38
|
+
### Embedded Provider (Multiple Auth Methods)
|
|
39
39
|
|
|
40
40
|
```typescript
|
|
41
41
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
42
42
|
|
|
43
|
-
// Create embedded non-custodial wallet
|
|
43
|
+
// Create embedded non-custodial wallet with multiple auth providers
|
|
44
44
|
const sdk = new BrowserSDK({
|
|
45
|
-
|
|
45
|
+
providers: ["google", "apple", "phantom"], // Allow Google, Apple, and Phantom Login
|
|
46
46
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
47
47
|
appId: "your-app-id", // Get your app ID from phantom.com/portal
|
|
48
48
|
});
|
|
@@ -72,14 +72,15 @@ After instantiating the SDK, use `sdk.connect()` to establish a connection to th
|
|
|
72
72
|
```typescript
|
|
73
73
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
74
74
|
|
|
75
|
-
// 1. Create SDK instance
|
|
75
|
+
// 1. Create SDK instance with allowed providers
|
|
76
76
|
const sdk = new BrowserSDK({
|
|
77
|
-
|
|
77
|
+
providers: ["google", "apple", "phantom", "injected"], // Allowed auth providers
|
|
78
78
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
79
|
+
appId: "your-app-id", // Required when using embedded providers
|
|
79
80
|
});
|
|
80
81
|
|
|
81
|
-
// 2. Connect to wallet (provider parameter
|
|
82
|
-
const { addresses } = await sdk.connect({ provider: "
|
|
82
|
+
// 2. Connect to wallet (provider parameter must be in allowed providers list)
|
|
83
|
+
const { addresses } = await sdk.connect({ provider: "google" });
|
|
83
84
|
console.log("Connected addresses:", addresses);
|
|
84
85
|
|
|
85
86
|
// 3. Use chain-specific methods
|
|
@@ -182,39 +183,50 @@ const accounts = await sdk.ethereum.getAccounts();
|
|
|
182
183
|
const isConnected = sdk.ethereum.isConnected();
|
|
183
184
|
```
|
|
184
185
|
|
|
185
|
-
##
|
|
186
|
+
## Authentication Providers
|
|
187
|
+
|
|
188
|
+
The SDK supports multiple authentication providers that you configure via the `providers` array:
|
|
189
|
+
|
|
190
|
+
### Available Providers
|
|
191
|
+
|
|
192
|
+
- **`"injected"`** - Phantom browser extension (no `appId` required)
|
|
193
|
+
- **`"google"`** - Google OAuth (requires `appId`)
|
|
194
|
+
- **`"apple"`** - Apple ID (requires `appId`)
|
|
195
|
+
- **`"phantom"`** - Phantom Login (requires `appId`)
|
|
196
|
+
- **`"x"`** - X/Twitter (requires `appId`)
|
|
197
|
+
- **`"tiktok"`** - TikTok (requires `appId`)
|
|
186
198
|
|
|
187
|
-
###
|
|
199
|
+
### Configuration Examples
|
|
188
200
|
|
|
189
|
-
|
|
201
|
+
**Injected Provider Only (Browser Extension)**
|
|
190
202
|
|
|
191
203
|
```typescript
|
|
192
204
|
const sdk = new BrowserSDK({
|
|
193
|
-
|
|
205
|
+
providers: ["injected"], // Only allow browser extension
|
|
194
206
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
195
207
|
});
|
|
196
208
|
```
|
|
197
209
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
Creates a non-custodial wallet embedded in your application. Requires API configuration.
|
|
210
|
+
**Multiple Authentication Methods**
|
|
201
211
|
|
|
202
212
|
```typescript
|
|
203
213
|
const sdk = new BrowserSDK({
|
|
204
|
-
|
|
214
|
+
providers: ["google", "apple", "phantom", "injected"], // Allow all methods
|
|
205
215
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
206
|
-
appId: "your-app-id", //
|
|
216
|
+
appId: "your-app-id", // Required for embedded providers (google, apple, phantom, x, tiktok)
|
|
207
217
|
authOptions: {
|
|
208
|
-
authUrl: "https://connect.phantom.app/login", // optional
|
|
218
|
+
authUrl: "https://connect.phantom.app/login", // optional
|
|
209
219
|
redirectUrl: "https://yourapp.com/callback", // optional, defaults to current page
|
|
210
220
|
},
|
|
211
|
-
autoConnect: true, // optional, auto-connect to existing session (default: true
|
|
221
|
+
autoConnect: true, // optional, auto-connect to existing session (default: true when embedded providers are used)
|
|
212
222
|
});
|
|
213
223
|
```
|
|
214
224
|
|
|
215
225
|
### Embedded Wallet Type
|
|
216
226
|
|
|
217
|
-
|
|
227
|
+
When using embedded providers (google, apple, phantom, etc.), you can specify the wallet type:
|
|
228
|
+
|
|
229
|
+
#### User Wallet (`'user-wallet'`) - Default
|
|
218
230
|
|
|
219
231
|
- **Uses Phantom authentication** - user logs in with existing Phantom account
|
|
220
232
|
- **Potentially funded** - brings in user's existing wallet balance
|
|
@@ -223,9 +235,10 @@ const sdk = new BrowserSDK({
|
|
|
223
235
|
|
|
224
236
|
```typescript
|
|
225
237
|
const sdk = new BrowserSDK({
|
|
226
|
-
|
|
238
|
+
providers: ["google", "apple", "phantom"],
|
|
227
239
|
appId: "your-app-id",
|
|
228
240
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
241
|
+
embeddedWalletType: "user-wallet", // default, can be omitted
|
|
229
242
|
});
|
|
230
243
|
```
|
|
231
244
|
|
|
@@ -236,17 +249,16 @@ const sdk = new BrowserSDK({
|
|
|
236
249
|
| `AddressType.solana` | Solana Mainnet, Devnet, Testnet |
|
|
237
250
|
| `AddressType.ethereum` | Ethereum, Polygon, Arbitrum, and more |
|
|
238
251
|
|
|
239
|
-
|
|
240
252
|
### Auto-Connect Feature
|
|
241
253
|
|
|
242
254
|
The SDK can automatically reconnect to existing sessions when instantiated, providing a seamless user experience.
|
|
243
255
|
|
|
244
256
|
```typescript
|
|
245
257
|
const sdk = new BrowserSDK({
|
|
246
|
-
|
|
258
|
+
providers: ["google", "apple", "phantom"],
|
|
247
259
|
appId: "your-app-id",
|
|
248
260
|
addressTypes: [AddressType.solana],
|
|
249
|
-
autoConnect: true, // Default: true
|
|
261
|
+
autoConnect: true, // Default: true when embedded providers are used, false for injected-only
|
|
250
262
|
});
|
|
251
263
|
|
|
252
264
|
// SDK will automatically check for existing valid session and connect in background
|
|
@@ -258,7 +270,7 @@ if (sdk.isConnected()) {
|
|
|
258
270
|
const addresses = await sdk.getAddresses();
|
|
259
271
|
} else {
|
|
260
272
|
// First time or session expired, need to connect manually
|
|
261
|
-
await sdk.connect();
|
|
273
|
+
await sdk.connect({ provider: "google" });
|
|
262
274
|
}
|
|
263
275
|
```
|
|
264
276
|
|
|
@@ -266,14 +278,14 @@ if (sdk.isConnected()) {
|
|
|
266
278
|
|
|
267
279
|
```typescript
|
|
268
280
|
const sdk = new BrowserSDK({
|
|
269
|
-
|
|
281
|
+
providers: ["google", "apple", "phantom"],
|
|
270
282
|
appId: "your-app-id",
|
|
271
283
|
addressTypes: [AddressType.solana],
|
|
272
284
|
autoConnect: false, // Disable auto-connect
|
|
273
285
|
});
|
|
274
286
|
|
|
275
287
|
// Now you must manually call connect() every time
|
|
276
|
-
await sdk.connect();
|
|
288
|
+
await sdk.connect({ provider: "google" });
|
|
277
289
|
```
|
|
278
290
|
|
|
279
291
|
## API Reference
|
|
@@ -288,21 +300,26 @@ new BrowserSDK(config: BrowserSDKConfig)
|
|
|
288
300
|
|
|
289
301
|
```typescript
|
|
290
302
|
interface BrowserSDKConfig {
|
|
291
|
-
|
|
303
|
+
// List of allowed authentication providers (REQUIRED)
|
|
304
|
+
providers: AuthProviderType[]; // e.g., ["google", "apple", "phantom", "injected"]
|
|
305
|
+
|
|
292
306
|
addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
|
|
293
307
|
|
|
294
|
-
// Required
|
|
295
|
-
appId?: string; // Your app ID from phantom.com/portal
|
|
296
|
-
|
|
308
|
+
// Required when using embedded providers (google, apple, phantom, x, tiktok)
|
|
309
|
+
appId?: string; // Your app ID from phantom.com/portal
|
|
310
|
+
|
|
297
311
|
// Optional configuration
|
|
298
312
|
apiBaseUrl?: string; // Phantom API base URL (optional, has default)
|
|
299
313
|
authOptions?: {
|
|
300
314
|
authUrl?: string; // Custom auth URL (optional, defaults to "https://connect.phantom.app/login")
|
|
301
315
|
redirectUrl?: string; // Custom redirect URL after authentication (optional)
|
|
302
316
|
};
|
|
303
|
-
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet"
|
|
304
|
-
autoConnect?: boolean; //
|
|
317
|
+
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet")
|
|
318
|
+
autoConnect?: boolean; // Auto-connect to existing session (default: true when embedded providers used)
|
|
305
319
|
}
|
|
320
|
+
|
|
321
|
+
// Valid provider types
|
|
322
|
+
type AuthProviderType = "google" | "apple" | "phantom" | "x" | "tiktok" | "injected";
|
|
306
323
|
```
|
|
307
324
|
|
|
308
325
|
### Extension Detection
|
|
@@ -347,6 +364,7 @@ if (isAvailable) {
|
|
|
347
364
|
Connect to wallet and get addresses for configured AddressTypes.
|
|
348
365
|
|
|
349
366
|
**Parameters:**
|
|
367
|
+
|
|
350
368
|
- `options: AuthOptions` (required) - Authentication options
|
|
351
369
|
- `provider: "google" | "apple" | "jwt" | "phantom" | "injected"` (required) - Authentication provider to use
|
|
352
370
|
- `jwtToken?: string` (optional) - JWT token (required when `provider` is "jwt")
|
|
@@ -362,7 +380,7 @@ const result = await sdk.connect({ provider: "phantom" });
|
|
|
362
380
|
// Connect with Google authentication
|
|
363
381
|
const result = await sdk.connect({ provider: "google" });
|
|
364
382
|
|
|
365
|
-
// Returns: { addresses: WalletAddress[], status: "pending" | "completed",
|
|
383
|
+
// Returns: { addresses: WalletAddress[], status: "pending" | "completed", provider: "google" | "apple" | "injected" ... }
|
|
366
384
|
// addresses only includes types from addressTypes config
|
|
367
385
|
```
|
|
368
386
|
|
|
@@ -544,7 +562,7 @@ const result = await sdk.ethereum.sendTransaction({
|
|
|
544
562
|
|
|
545
563
|
#### switchChain(chainId)
|
|
546
564
|
|
|
547
|
-
Switch to a different Ethereum chain.
|
|
565
|
+
Switch to a different Ethereum chain. Accepts a chain ID as a number or a hex string value.
|
|
548
566
|
|
|
549
567
|
```typescript
|
|
550
568
|
await sdk.ethereum.switchChain(1); // Ethereum mainnet
|
|
@@ -552,6 +570,21 @@ await sdk.ethereum.switchChain(137); // Polygon
|
|
|
552
570
|
await sdk.ethereum.switchChain(42161); // Arbitrum One
|
|
553
571
|
```
|
|
554
572
|
|
|
573
|
+
**Supported EVM Networks:**
|
|
574
|
+
|
|
575
|
+
| Network | Chain ID | Usage |
|
|
576
|
+
| ---------------- | ---------- | ----------------------- |
|
|
577
|
+
| Ethereum Mainnet | `1` | `switchChain(1)` |
|
|
578
|
+
| Ethereum Sepolia | `11155111` | `switchChain(11155111)` |
|
|
579
|
+
| Polygon Mainnet | `137` | `switchChain(137)` |
|
|
580
|
+
| Polygon Amoy | `80002` | `switchChain(80002)` |
|
|
581
|
+
| Base Mainnet | `8453` | `switchChain(8453)` |
|
|
582
|
+
| Base Sepolia | `84532` | `switchChain(84532)` |
|
|
583
|
+
| Arbitrum One | `42161` | `switchChain(42161)` |
|
|
584
|
+
| Arbitrum Sepolia | `421614` | `switchChain(421614)` |
|
|
585
|
+
| Monad Mainnet | `143` | `switchChain(143)` |
|
|
586
|
+
| Monad Testnet | `10143` | `switchChain(10143)` |
|
|
587
|
+
|
|
555
588
|
#### getChainId()
|
|
556
589
|
|
|
557
590
|
Get the current chain ID.
|
|
@@ -594,66 +627,66 @@ The SDK provides typed event handlers that allow you to listen for connection st
|
|
|
594
627
|
#### Available Events
|
|
595
628
|
|
|
596
629
|
```typescript
|
|
597
|
-
import { BrowserSDK } from
|
|
630
|
+
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
598
631
|
import type {
|
|
599
632
|
ConnectEventData,
|
|
600
633
|
ConnectStartEventData,
|
|
601
634
|
ConnectErrorEventData,
|
|
602
|
-
DisconnectEventData
|
|
603
|
-
} from
|
|
635
|
+
DisconnectEventData,
|
|
636
|
+
} from "@phantom/browser-sdk";
|
|
604
637
|
|
|
605
638
|
const sdk = new BrowserSDK({
|
|
606
|
-
|
|
607
|
-
appId:
|
|
639
|
+
providers: ["google", "apple", "phantom"],
|
|
640
|
+
appId: "your-app-id",
|
|
608
641
|
addressTypes: [AddressType.solana],
|
|
609
642
|
});
|
|
610
643
|
|
|
611
644
|
// 1. connect_start - Fired when connection starts
|
|
612
|
-
sdk.on(
|
|
613
|
-
console.log(
|
|
614
|
-
console.log(
|
|
645
|
+
sdk.on("connect_start", (data: ConnectStartEventData) => {
|
|
646
|
+
console.log("Connection starting:", data.source); // "auto-connect" | "manual-connect"
|
|
647
|
+
console.log("Auth options:", data.authOptions?.provider); // "google" | "apple" | etc.
|
|
615
648
|
});
|
|
616
649
|
|
|
617
650
|
// 2. connect - Fired when connection succeeds (includes full ConnectResult)
|
|
618
|
-
sdk.on(
|
|
619
|
-
console.log(
|
|
620
|
-
console.log(
|
|
621
|
-
console.log(
|
|
622
|
-
console.log(
|
|
623
|
-
console.log(
|
|
624
|
-
console.log(
|
|
651
|
+
sdk.on("connect", (data: ConnectEventData) => {
|
|
652
|
+
console.log("Connected successfully!");
|
|
653
|
+
console.log("Provider type:", data.provider); // "google" | "apple" | "injected" ...
|
|
654
|
+
console.log("Wallet ID:", data.walletId); // only for embedded providers
|
|
655
|
+
console.log("Addresses:", data.addresses); // WalletAddress[]
|
|
656
|
+
console.log("Status:", data.status); // "pending" | "completed"
|
|
657
|
+
console.log("Source:", data.source); // "auto-connect" | "manual-connect" | "manual-existing" | "existing-session" | "manual"
|
|
625
658
|
});
|
|
626
659
|
|
|
627
660
|
// 3. connect_error - Fired when connection fails
|
|
628
|
-
sdk.on(
|
|
629
|
-
console.error(
|
|
630
|
-
console.log(
|
|
661
|
+
sdk.on("connect_error", (data: ConnectErrorEventData) => {
|
|
662
|
+
console.error("Connection failed:", data.error);
|
|
663
|
+
console.log("Source:", data.source); // "auto-connect" | "manual-connect"
|
|
631
664
|
});
|
|
632
665
|
|
|
633
666
|
// 4. disconnect - Fired when disconnected
|
|
634
|
-
sdk.on(
|
|
635
|
-
console.log(
|
|
636
|
-
console.log(
|
|
667
|
+
sdk.on("disconnect", (data: DisconnectEventData) => {
|
|
668
|
+
console.log("Disconnected from wallet");
|
|
669
|
+
console.log("Source:", data.source); // "manual"
|
|
637
670
|
});
|
|
638
671
|
|
|
639
672
|
// 5. error - General error handler
|
|
640
|
-
sdk.on(
|
|
641
|
-
console.error(
|
|
673
|
+
sdk.on("error", (error: unknown) => {
|
|
674
|
+
console.error("SDK error:", error);
|
|
642
675
|
});
|
|
643
676
|
|
|
644
677
|
// Don't forget to remove listeners when done
|
|
645
|
-
sdk.off(
|
|
678
|
+
sdk.off("connect", handleConnect);
|
|
646
679
|
```
|
|
647
680
|
|
|
648
681
|
#### Event Types
|
|
649
682
|
|
|
650
|
-
| Event
|
|
651
|
-
|
|
652
|
-
| `connect_start` | `ConnectStartEventData` | Connection initiated
|
|
653
|
-
| `connect`
|
|
654
|
-
| `connect_error` | `ConnectErrorEventData` | Connection failed
|
|
655
|
-
| `disconnect`
|
|
656
|
-
| `error`
|
|
683
|
+
| Event | Payload Type | When Fired | Key Data |
|
|
684
|
+
| --------------- | ----------------------- | --------------------- | --------------------------------------------------- |
|
|
685
|
+
| `connect_start` | `ConnectStartEventData` | Connection initiated | `source`, `authOptions` |
|
|
686
|
+
| `connect` | `ConnectEventData` | Connection successful | `provider`, `addresses`, `status`, `source`, `user` |
|
|
687
|
+
| `connect_error` | `ConnectErrorEventData` | Connection failed | `error`, `source` |
|
|
688
|
+
| `disconnect` | `DisconnectEventData` | Disconnected | `source` |
|
|
689
|
+
| `error` | `unknown` | General SDK errors | Error details |
|
|
657
690
|
|
|
658
691
|
#### Using Events with autoConnect()
|
|
659
692
|
|
|
@@ -661,24 +694,24 @@ Event handlers are especially useful with `autoConnect()` since it doesn't retur
|
|
|
661
694
|
|
|
662
695
|
```typescript
|
|
663
696
|
const sdk = new BrowserSDK({
|
|
664
|
-
|
|
665
|
-
appId:
|
|
697
|
+
providers: ["google", "apple", "phantom"],
|
|
698
|
+
appId: "your-app-id",
|
|
666
699
|
addressTypes: [AddressType.solana],
|
|
667
700
|
autoConnect: true,
|
|
668
701
|
});
|
|
669
702
|
|
|
670
703
|
// Set up event listeners BEFORE autoConnect
|
|
671
|
-
sdk.on(
|
|
672
|
-
console.log(
|
|
673
|
-
console.log(
|
|
674
|
-
console.log(
|
|
704
|
+
sdk.on("connect", (data: ConnectEventData) => {
|
|
705
|
+
console.log("Auto-connected successfully!");
|
|
706
|
+
console.log("Provider type:", data.provider);
|
|
707
|
+
console.log("Addresses:", data.addresses);
|
|
675
708
|
|
|
676
709
|
// Update your UI state here
|
|
677
710
|
updateUIWithAddresses(data.addresses);
|
|
678
711
|
});
|
|
679
712
|
|
|
680
|
-
sdk.on(
|
|
681
|
-
console.log(
|
|
713
|
+
sdk.on("connect_error", (data: ConnectErrorEventData) => {
|
|
714
|
+
console.log("Auto-connect failed:", data.error);
|
|
682
715
|
// Show connect button to user
|
|
683
716
|
showConnectButton();
|
|
684
717
|
});
|
|
@@ -744,33 +777,15 @@ console.log("Supported chains:", supportedChains.chains);
|
|
|
744
777
|
|
|
745
778
|
#### Available NetworkId Values
|
|
746
779
|
|
|
780
|
+
For a complete list of supported networks including Solana, Ethereum, Polygon, Base, Arbitrum, Monad, and more, see the [Network Support section in the main README](../../README.md#network-support).
|
|
781
|
+
|
|
747
782
|
```typescript
|
|
748
783
|
import { NetworkId } from "@phantom/browser-sdk";
|
|
749
784
|
|
|
750
|
-
//
|
|
751
|
-
|
|
752
|
-
NetworkId.
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
// Ethereum networks
|
|
756
|
-
NetworkId.ETHEREUM_MAINNET; // "eip155:1"
|
|
757
|
-
NetworkId.ETHEREUM_SEPOLIA; // "eip155:11155111"
|
|
758
|
-
|
|
759
|
-
// Polygon networks
|
|
760
|
-
NetworkId.POLYGON_MAINNET; // "eip155:137"
|
|
761
|
-
NetworkId.POLYGON_AMOY; // "eip155:80002"
|
|
762
|
-
|
|
763
|
-
// Arbitrum networks
|
|
764
|
-
NetworkId.ARBITRUM_ONE; // "eip155:42161"
|
|
765
|
-
NetworkId.ARBITRUM_SEPOLIA; // "eip155:421614"
|
|
766
|
-
|
|
767
|
-
// Optimism networks
|
|
768
|
-
NetworkId.OPTIMISM_MAINNET; // "eip155:10"
|
|
769
|
-
NetworkId.OPTIMISM_GOERLI; // "eip155:420"
|
|
770
|
-
|
|
771
|
-
// Base networks
|
|
772
|
-
NetworkId.BASE_MAINNET; // "eip155:8453"
|
|
773
|
-
NetworkId.BASE_SEPOLIA; // "eip155:84532"
|
|
785
|
+
// Example: Use NetworkId for auto-confirm
|
|
786
|
+
await sdk.enableAutoConfirm({
|
|
787
|
+
chains: [NetworkId.SOLANA_MAINNET, NetworkId.ETHEREUM_MAINNET],
|
|
788
|
+
});
|
|
774
789
|
```
|
|
775
790
|
|
|
776
791
|
**Important Notes:**
|
|
@@ -841,11 +856,12 @@ interface DebugMessage {
|
|
|
841
856
|
### Example: Debug Console Implementation
|
|
842
857
|
|
|
843
858
|
```typescript
|
|
844
|
-
import { BrowserSDK, DebugLevel } from "@phantom/browser-sdk";
|
|
859
|
+
import { BrowserSDK, DebugLevel, AddressType } from "@phantom/browser-sdk";
|
|
845
860
|
|
|
846
861
|
const sdk = new BrowserSDK({
|
|
847
|
-
|
|
862
|
+
providers: ["google", "apple", "phantom"],
|
|
848
863
|
appId: "your-app-id",
|
|
864
|
+
addressTypes: [AddressType.solana],
|
|
849
865
|
});
|
|
850
866
|
|
|
851
867
|
// Store debug messages
|
|
@@ -910,7 +926,7 @@ import {
|
|
|
910
926
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
911
927
|
|
|
912
928
|
const sdk = new BrowserSDK({
|
|
913
|
-
|
|
929
|
+
providers: ["injected"],
|
|
914
930
|
addressTypes: [AddressType.solana],
|
|
915
931
|
});
|
|
916
932
|
|
|
@@ -963,7 +979,7 @@ import {
|
|
|
963
979
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
964
980
|
|
|
965
981
|
const sdk = new BrowserSDK({
|
|
966
|
-
|
|
982
|
+
providers: ["injected"],
|
|
967
983
|
addressTypes: [AddressType.solana],
|
|
968
984
|
});
|
|
969
985
|
|
|
@@ -993,7 +1009,7 @@ console.log("Transaction signature:", result.hash);
|
|
|
993
1009
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
994
1010
|
|
|
995
1011
|
const sdk = new BrowserSDK({
|
|
996
|
-
|
|
1012
|
+
providers: ["injected"],
|
|
997
1013
|
addressTypes: [AddressType.ethereum],
|
|
998
1014
|
});
|
|
999
1015
|
|
|
@@ -1027,9 +1043,9 @@ import { parseEther, parseGwei, encodeFunctionData } from "viem";
|
|
|
1027
1043
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
1028
1044
|
|
|
1029
1045
|
const sdk = new BrowserSDK({
|
|
1030
|
-
|
|
1046
|
+
providers: ["google", "apple", "phantom"],
|
|
1047
|
+
appId: "your-app-id",
|
|
1031
1048
|
addressTypes: [AddressType.ethereum],
|
|
1032
|
-
// ... config
|
|
1033
1049
|
});
|
|
1034
1050
|
|
|
1035
1051
|
// Simple transfer with viem utilities
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EmbeddedProviderConfig,
|
|
2
|
-
export {
|
|
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
3
|
import { ISolanaChain, IEthereumChain } from '@phantom/chain-interfaces';
|
|
4
4
|
export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chain-interfaces';
|
|
5
5
|
import { AddressType } from '@phantom/client';
|
|
@@ -52,9 +52,6 @@ declare const DebugCategory: {
|
|
|
52
52
|
readonly SESSION: "Session";
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
/**
|
|
56
|
-
* Phantom extension app.login API types
|
|
57
|
-
*/
|
|
58
55
|
interface PhantomAppLoginOptions {
|
|
59
56
|
publicKey: string;
|
|
60
57
|
appId: string;
|
|
@@ -95,30 +92,30 @@ interface DebugConfig {
|
|
|
95
92
|
level?: DebugLevel;
|
|
96
93
|
callback?: DebugCallback;
|
|
97
94
|
}
|
|
98
|
-
type BrowserSDKConfig = Prettify<
|
|
99
|
-
|
|
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";
|
|
95
|
+
type BrowserSDKConfig = Prettify<Omit<EmbeddedProviderConfig, "authOptions" | "apiBaseUrl" | "embeddedWalletType" | "appId"> & InjectedProviderConfig & {
|
|
96
|
+
providers: AuthProviderType[];
|
|
97
|
+
appId?: string;
|
|
106
98
|
apiBaseUrl?: string;
|
|
107
99
|
embeddedWalletType?: "app-wallet" | "user-wallet";
|
|
108
100
|
authOptions?: {
|
|
109
101
|
authUrl?: string;
|
|
110
102
|
redirectUrl?: string;
|
|
111
103
|
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
104
|
+
}>;
|
|
105
|
+
type Prettify<T> = {
|
|
106
|
+
[K in keyof T]: T[K];
|
|
107
|
+
} & {};
|
|
108
|
+
type AuthProviderType = EmbeddedProviderAuthType | "injected";
|
|
109
|
+
type AuthOptions = {
|
|
110
|
+
provider: AuthProviderType;
|
|
111
|
+
customAuthData?: Record<string, any>;
|
|
112
|
+
};
|
|
113
|
+
type ConnectResult = Omit<ConnectResult$1, "authProvider"> & {
|
|
114
|
+
authProvider?: AuthProviderType | undefined;
|
|
115
|
+
};
|
|
119
116
|
|
|
120
117
|
interface Provider {
|
|
121
|
-
connect(authOptions
|
|
118
|
+
connect(authOptions: AuthOptions): Promise<ConnectResult>;
|
|
122
119
|
disconnect(): Promise<void>;
|
|
123
120
|
getAddresses(): WalletAddress[];
|
|
124
121
|
isConnected(): boolean;
|
|
@@ -132,19 +129,6 @@ interface ProviderPreference {
|
|
|
132
129
|
embeddedWalletType?: "app-wallet" | "user-wallet";
|
|
133
130
|
}
|
|
134
131
|
|
|
135
|
-
/**
|
|
136
|
-
* Browser SDK with chain-specific API
|
|
137
|
-
*
|
|
138
|
-
* Usage:
|
|
139
|
-
* ```typescript
|
|
140
|
-
* const sdk = new BrowserSDK({ providerType: 'embedded', appId: 'your-app-id' });
|
|
141
|
-
* await sdk.connect();
|
|
142
|
-
*
|
|
143
|
-
* // Chain-specific operations
|
|
144
|
-
* await sdk.solana.signMessage(message);
|
|
145
|
-
* await sdk.ethereum.signPersonalMessage(message, address);
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
132
|
declare class BrowserSDK {
|
|
149
133
|
private providerManager;
|
|
150
134
|
constructor(config: BrowserSDKConfig);
|
|
@@ -326,4 +310,4 @@ declare function waitForPhantomExtension(timeoutMs?: number): Promise<boolean>;
|
|
|
326
310
|
*/
|
|
327
311
|
declare function isPhantomLoginAvailable(timeoutMs?: number): Promise<boolean>;
|
|
328
312
|
|
|
329
|
-
export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getDeeplinkToPhantom, getPlatformName, isMobileDevice, isPhantomLoginAvailable, parseBrowserFromUserAgent, waitForPhantomExtension };
|
|
313
|
+
export { AuthOptions, AuthProviderType, BrowserInfo, BrowserSDK, BrowserSDKConfig, ConnectResult, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getDeeplinkToPhantom, getPlatformName, isMobileDevice, isPhantomLoginAvailable, parseBrowserFromUserAgent, waitForPhantomExtension };
|