@phantom/browser-sdk 1.0.0-beta.0 → 1.0.0-beta.1

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 CHANGED
@@ -45,7 +45,7 @@ const sdk = new BrowserSDK({
45
45
  providerType: "embedded",
46
46
  addressTypes: [AddressType.solana, AddressType.ethereum],
47
47
  apiBaseUrl: "https://api.phantom.app/v1/wallets",
48
- organizationId: "your-org-id",
48
+ appId: "your-app-id",
49
49
  });
50
50
 
51
51
  const { addresses } = await sdk.connect();
@@ -107,7 +107,7 @@ const result = await sdk.connect({
107
107
  },
108
108
  });
109
109
 
110
- // Apple authentication (skips provider selection)
110
+ // Apple authentication (skips provider selection)
111
111
  const result = await sdk.connect({
112
112
  authOptions: {
113
113
  provider: "apple",
@@ -132,7 +132,7 @@ const signedTx = await sdk.solana.signTransaction(transaction);
132
132
  const result = await sdk.solana.signAndSendTransaction(transaction);
133
133
 
134
134
  // Network switching
135
- await sdk.solana.switchNetwork('devnet');
135
+ await sdk.solana.switchNetwork("devnet");
136
136
 
137
137
  // Utilities
138
138
  const publicKey = await sdk.solana.getPublicKey();
@@ -143,8 +143,8 @@ const isConnected = sdk.solana.isConnected();
143
143
 
144
144
  ```typescript
145
145
  // EIP-1193 requests
146
- const accounts = await sdk.ethereum.request({ method: 'eth_accounts' });
147
- const chainId = await sdk.ethereum.request({ method: 'eth_chainId' });
146
+ const accounts = await sdk.ethereum.request({ method: "eth_accounts" });
147
+ const chainId = await sdk.ethereum.request({ method: "eth_chainId" });
148
148
 
149
149
  // Message signing
150
150
  const signature = await sdk.ethereum.signPersonalMessage(message, address);
@@ -191,14 +191,12 @@ const sdk = new BrowserSDK({
191
191
  providerType: "embedded",
192
192
  addressTypes: [AddressType.solana, AddressType.ethereum],
193
193
  apiBaseUrl: "https://api.phantom.app/v1/wallets",
194
- organizationId: "your-org-id",
194
+ appId: "your-app-id",
195
195
  embeddedWalletType: "app-wallet", // or 'user-wallet'
196
196
  authOptions: {
197
197
  authUrl: "https://auth.phantom.app", // optional, defaults to "https://connect.phantom.app"
198
198
  redirectUrl: "https://yourapp.com/callback", // optional, defaults to current page
199
199
  },
200
- appName: "My DApp", // optional, for branding
201
- appLogo: "https://myapp.com/logo.png", // optional, for branding
202
200
  autoConnect: true, // optional, auto-connect to existing session (default: true for embedded)
203
201
  });
204
202
  ```
@@ -239,10 +237,10 @@ const sdk = new BrowserSDK({
239
237
 
240
238
  ### Available AddressTypes
241
239
 
242
- | AddressType | Supported Chains |
243
- | --------------------------- | ----------------------------------- |
244
- | `AddressType.solana` | Solana Mainnet, Devnet, Testnet |
245
- | `AddressType.ethereum` | Ethereum, Polygon, Arbitrum, and more |
240
+ | AddressType | Supported Chains |
241
+ | ---------------------- | ------------------------------------- |
242
+ | `AddressType.solana` | Solana Mainnet, Devnet, Testnet |
243
+ | `AddressType.ethereum` | Ethereum, Polygon, Arbitrum, and more |
246
244
 
247
245
  ### Solana Provider Configuration
248
246
 
@@ -319,13 +317,11 @@ new BrowserSDK(config: BrowserSDKConfig)
319
317
  ```typescript
320
318
  interface BrowserSDKConfig {
321
319
  providerType: "injected" | "embedded";
322
- appName?: string; // Optional app name for branding
323
- appLogo?: string; // Optional app logo URL for branding
324
320
  addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
325
321
 
326
322
  // Required for embedded provider only
327
323
  apiBaseUrl?: string; // Phantom API base URL
328
- organizationId?: string; // Your organization ID
324
+ appId?: string; // Your app ID (required for embedded provider)
329
325
  authOptions?: {
330
326
  authUrl?: string; // Custom auth URL (default: "https://connect.phantom.app")
331
327
  redirectUrl?: string; // Custom redirect URL after authentication
@@ -336,6 +332,22 @@ interface BrowserSDKConfig {
336
332
  }
337
333
  ```
338
334
 
335
+ ### Extension Detection
336
+
337
+ For injected provider usage, you can check if the Phantom extension is installed:
338
+
339
+ ```typescript
340
+ import { waitForPhantomExtension } from "@phantom/browser-sdk";
341
+
342
+ const isAvailable = await waitForPhantomExtension(5000);
343
+
344
+ if (isAvailable) {
345
+ console.log("Phantom extension is available!");
346
+ } else {
347
+ console.log("Phantom extension not found");
348
+ }
349
+ ```
350
+
339
351
  ### Core Methods
340
352
 
341
353
  #### connect()
@@ -416,8 +428,8 @@ const result = await sdk.solana.signAndSendTransaction(transaction);
416
428
  Switch between Solana networks.
417
429
 
418
430
  ```typescript
419
- await sdk.solana.switchNetwork('mainnet');
420
- await sdk.solana.switchNetwork('devnet');
431
+ await sdk.solana.switchNetwork("mainnet");
432
+ await sdk.solana.switchNetwork("devnet");
421
433
  ```
422
434
 
423
435
  #### getPublicKey()
@@ -445,11 +457,11 @@ const connected = sdk.solana.isConnected();
445
457
  Make an EIP-1193 compatible request.
446
458
 
447
459
  ```typescript
448
- const accounts = await sdk.ethereum.request({ method: 'eth_accounts' });
449
- const chainId = await sdk.ethereum.request({ method: 'eth_chainId' });
450
- const balance = await sdk.ethereum.request({
451
- method: 'eth_getBalance',
452
- params: [address, 'latest']
460
+ const accounts = await sdk.ethereum.request({ method: "eth_accounts" });
461
+ const chainId = await sdk.ethereum.request({ method: "eth_chainId" });
462
+ const balance = await sdk.ethereum.request({
463
+ method: "eth_getBalance",
464
+ params: [address, "latest"],
453
465
  });
454
466
  ```
455
467
 
@@ -473,26 +485,26 @@ const typedData = {
473
485
  { name: "name", type: "string" },
474
486
  { name: "version", type: "string" },
475
487
  { name: "chainId", type: "uint256" },
476
- { name: "verifyingContract", type: "address" }
488
+ { name: "verifyingContract", type: "address" },
477
489
  ],
478
490
  Mail: [
479
491
  { name: "from", type: "string" },
480
492
  { name: "to", type: "string" },
481
- { name: "contents", type: "string" }
482
- ]
493
+ { name: "contents", type: "string" },
494
+ ],
483
495
  },
484
496
  primaryType: "Mail",
485
497
  domain: {
486
498
  name: "Ether Mail",
487
499
  version: "1",
488
500
  chainId: 1,
489
- verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
501
+ verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
490
502
  },
491
503
  message: {
492
504
  from: "Alice",
493
505
  to: "Bob",
494
- contents: "Hello!"
495
- }
506
+ contents: "Hello!",
507
+ },
496
508
  };
497
509
 
498
510
  const signature = await sdk.ethereum.signTypedData(typedData, address);
@@ -518,8 +530,8 @@ const result = await sdk.ethereum.sendTransaction({
518
530
  Switch to a different Ethereum chain.
519
531
 
520
532
  ```typescript
521
- await sdk.ethereum.switchChain(1); // Ethereum mainnet
522
- await sdk.ethereum.switchChain(137); // Polygon
533
+ await sdk.ethereum.switchChain(1); // Ethereum mainnet
534
+ await sdk.ethereum.switchChain(137); // Polygon
523
535
  await sdk.ethereum.switchChain(42161); // Arbitrum One
524
536
  ```
525
537
 
@@ -571,10 +583,10 @@ import { NetworkId } from "@phantom/browser-sdk";
571
583
 
572
584
  // Enable auto-confirm for specific chains
573
585
  const result = await sdk.enableAutoConfirm({
574
- chains: [NetworkId.SOLANA_MAINNET, NetworkId.ETHEREUM_MAINNET]
586
+ chains: [NetworkId.SOLANA_MAINNET, NetworkId.ETHEREUM_MAINNET],
575
587
  });
576
588
 
577
- // Enable auto-confirm for all supported chains
589
+ // Enable auto-confirm for all supported chains
578
590
  const result = await sdk.enableAutoConfirm();
579
591
 
580
592
  console.log("Auto-confirm enabled:", result.enabled);
@@ -619,29 +631,29 @@ console.log("Supported chains:", supportedChains.chains);
619
631
  import { NetworkId } from "@phantom/browser-sdk";
620
632
 
621
633
  // Solana networks
622
- NetworkId.SOLANA_MAINNET // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
623
- NetworkId.SOLANA_DEVNET // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
624
- NetworkId.SOLANA_TESTNET // "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
634
+ NetworkId.SOLANA_MAINNET; // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
635
+ NetworkId.SOLANA_DEVNET; // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
636
+ NetworkId.SOLANA_TESTNET; // "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
625
637
 
626
638
  // Ethereum networks
627
- NetworkId.ETHEREUM_MAINNET // "eip155:1"
628
- NetworkId.ETHEREUM_SEPOLIA // "eip155:11155111"
639
+ NetworkId.ETHEREUM_MAINNET; // "eip155:1"
640
+ NetworkId.ETHEREUM_SEPOLIA; // "eip155:11155111"
629
641
 
630
- // Polygon networks
631
- NetworkId.POLYGON_MAINNET // "eip155:137"
632
- NetworkId.POLYGON_AMOY // "eip155:80002"
642
+ // Polygon networks
643
+ NetworkId.POLYGON_MAINNET; // "eip155:137"
644
+ NetworkId.POLYGON_AMOY; // "eip155:80002"
633
645
 
634
646
  // Arbitrum networks
635
- NetworkId.ARBITRUM_ONE // "eip155:42161"
636
- NetworkId.ARBITRUM_SEPOLIA // "eip155:421614"
647
+ NetworkId.ARBITRUM_ONE; // "eip155:42161"
648
+ NetworkId.ARBITRUM_SEPOLIA; // "eip155:421614"
637
649
 
638
650
  // Optimism networks
639
- NetworkId.OPTIMISM_MAINNET // "eip155:10"
640
- NetworkId.OPTIMISM_GOERLI // "eip155:420"
651
+ NetworkId.OPTIMISM_MAINNET; // "eip155:10"
652
+ NetworkId.OPTIMISM_GOERLI; // "eip155:420"
641
653
 
642
654
  // Base networks
643
- NetworkId.BASE_MAINNET // "eip155:8453"
644
- NetworkId.BASE_SEPOLIA // "eip155:84532"
655
+ NetworkId.BASE_MAINNET; // "eip155:8453"
656
+ NetworkId.BASE_SEPOLIA; // "eip155:84532"
645
657
  ```
646
658
 
647
659
  **Important Notes:**
@@ -661,14 +673,14 @@ The BrowserSDK provides dynamic debug configuration that can be changed at runti
661
673
  // Enable debug logging
662
674
  sdk.enableDebug();
663
675
 
664
- // Disable debug logging
676
+ // Disable debug logging
665
677
  sdk.disableDebug();
666
678
 
667
679
  // Set debug level
668
680
  sdk.setDebugLevel(DebugLevel.INFO);
669
681
 
670
682
  // Set debug callback function
671
- sdk.setDebugCallback((message) => {
683
+ sdk.setDebugCallback(message => {
672
684
  console.log(`[${message.category}] ${message.message}`, message.data);
673
685
  });
674
686
 
@@ -676,10 +688,10 @@ sdk.setDebugCallback((message) => {
676
688
  sdk.configureDebug({
677
689
  enabled: true,
678
690
  level: DebugLevel.DEBUG,
679
- callback: (message) => {
691
+ callback: message => {
680
692
  // Handle debug messages
681
693
  console.log(`[${message.level}] ${message.category}: ${message.message}`);
682
- }
694
+ },
683
695
  });
684
696
  ```
685
697
 
@@ -689,10 +701,10 @@ sdk.configureDebug({
689
701
  import { DebugLevel } from "@phantom/browser-sdk";
690
702
 
691
703
  // Available debug levels (in order of verbosity)
692
- DebugLevel.ERROR // 0 - Only error messages
693
- DebugLevel.WARN // 1 - Warning and error messages
694
- DebugLevel.INFO // 2 - Info, warning, and error messages
695
- DebugLevel.DEBUG // 3 - All debug messages (most verbose)
704
+ DebugLevel.ERROR; // 0 - Only error messages
705
+ DebugLevel.WARN; // 1 - Warning and error messages
706
+ DebugLevel.INFO; // 2 - Info, warning, and error messages
707
+ DebugLevel.DEBUG; // 3 - All debug messages (most verbose)
696
708
  ```
697
709
 
698
710
  ### Debug Message Structure
@@ -701,11 +713,11 @@ Debug callbacks receive a `DebugMessage` object:
701
713
 
702
714
  ```typescript
703
715
  interface DebugMessage {
704
- timestamp: number; // Unix timestamp
705
- level: DebugLevel; // Message level
706
- category: string; // Component category (e.g., "BrowserSDK", "ProviderManager")
707
- message: string; // Debug message text
708
- data?: any; // Additional debug data (optional)
716
+ timestamp: number; // Unix timestamp
717
+ level: DebugLevel; // Message level
718
+ category: string; // Component category (e.g., "BrowserSDK", "ProviderManager")
719
+ message: string; // Debug message text
720
+ data?: any; // Additional debug data (optional)
709
721
  }
710
722
  ```
711
723
 
@@ -726,17 +738,17 @@ const debugMessages: DebugMessage[] = [];
726
738
  sdk.configureDebug({
727
739
  enabled: true,
728
740
  level: DebugLevel.INFO,
729
- callback: (message) => {
741
+ callback: message => {
730
742
  debugMessages.push(message);
731
-
743
+
732
744
  // Keep only last 100 messages
733
745
  if (debugMessages.length > 100) {
734
746
  debugMessages.shift();
735
747
  }
736
-
748
+
737
749
  // Update UI
738
750
  updateDebugConsole();
739
- }
751
+ },
740
752
  });
741
753
 
742
754
  // Dynamic debug level changing
@@ -835,7 +847,7 @@ import {
835
847
  import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
836
848
 
837
849
  const sdk = new BrowserSDK({
838
- providerType: "injected",
850
+ providerType: "injected",
839
851
  addressTypes: [AddressType.solana],
840
852
  solanaProvider: "kit",
841
853
  });
@@ -926,4 +938,3 @@ const result = await sdk.ethereum.sendTransaction({
926
938
  maxPriorityFeePerGas: parseGwei("2").toString(),
927
939
  });
928
940
  ```
929
-
package/dist/index.d.ts CHANGED
@@ -61,7 +61,7 @@ interface BrowserSDKConfig extends Partial<EmbeddedProviderConfig> {
61
61
  providerType: "injected" | "embedded" | (string & Record<never, never>);
62
62
  addressTypes: [AddressType, ...AddressType[]];
63
63
  apiBaseUrl?: string;
64
- organizationId?: string;
64
+ appId?: string;
65
65
  embeddedWalletType?: "app-wallet" | "user-wallet" | (string & Record<never, never>);
66
66
  autoConnect?: boolean;
67
67
  }
@@ -138,7 +138,7 @@ declare class BrowserSDK {
138
138
  /**
139
139
  * Check if Phantom extension is installed
140
140
  */
141
- static isPhantomInstalled(): boolean;
141
+ static isPhantomInstalled(timeoutMs?: number): Promise<boolean>;
142
142
  /**
143
143
  * Add event listener for provider events (connect, connect_start, connect_error, disconnect, error)
144
144
  * Works with both embedded and injected providers
@@ -238,4 +238,22 @@ declare function getPlatformName(): string;
238
238
  */
239
239
  declare function getBrowserDisplayName(): string;
240
240
 
241
- export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DEFAULT_AUTH_URL, DEFAULT_WALLET_API_URL, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getPlatformName, parseBrowserFromUserAgent };
241
+ /**
242
+ * Wait for Phantom extension to be available with retry logic
243
+ *
244
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 3000)
245
+ * @returns Promise<boolean> - true if Phantom extension is available, false if timeout reached
246
+ *
247
+ * Usage:
248
+ * ```typescript
249
+ * const isAvailable = await waitForPhantomExtension(5000);
250
+ * if (isAvailable) {
251
+ * console.log("Phantom extension is available!");
252
+ * } else {
253
+ * console.log("Phantom extension not found or timed out");
254
+ * }
255
+ * ```
256
+ */
257
+ declare function waitForPhantomExtension(timeoutMs?: number): Promise<boolean>;
258
+
259
+ export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DEFAULT_AUTH_URL, DEFAULT_WALLET_API_URL, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getPlatformName, parseBrowserFromUserAgent, waitForPhantomExtension };