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

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,17 @@ 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"],
465
+ });
466
+
467
+ // Sign transaction via RPC (alternative to signTransaction method)
468
+ const signedTx = await sdk.ethereum.request({
469
+ method: "eth_signTransaction",
470
+ params: [{ to: "0x...", value: "0x...", gas: "0x..." }],
453
471
  });
454
472
  ```
455
473
 
@@ -473,32 +491,46 @@ const typedData = {
473
491
  { name: "name", type: "string" },
474
492
  { name: "version", type: "string" },
475
493
  { name: "chainId", type: "uint256" },
476
- { name: "verifyingContract", type: "address" }
494
+ { name: "verifyingContract", type: "address" },
477
495
  ],
478
496
  Mail: [
479
497
  { name: "from", type: "string" },
480
498
  { name: "to", type: "string" },
481
- { name: "contents", type: "string" }
482
- ]
499
+ { name: "contents", type: "string" },
500
+ ],
483
501
  },
484
502
  primaryType: "Mail",
485
503
  domain: {
486
504
  name: "Ether Mail",
487
505
  version: "1",
488
506
  chainId: 1,
489
- verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
507
+ verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
490
508
  },
491
509
  message: {
492
510
  from: "Alice",
493
511
  to: "Bob",
494
- contents: "Hello!"
495
- }
512
+ contents: "Hello!",
513
+ },
496
514
  };
497
515
 
498
516
  const signature = await sdk.ethereum.signTypedData(typedData, address);
499
517
  // Returns: { signature: string, rawSignature: string }
500
518
  ```
501
519
 
520
+ #### signTransaction(transaction)
521
+
522
+ Sign an Ethereum transaction without sending it.
523
+
524
+ ```typescript
525
+ const signedTx = await sdk.ethereum.signTransaction({
526
+ to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
527
+ value: "1000000000000000000", // 1 ETH in wei
528
+ gas: "21000",
529
+ gasPrice: "20000000000", // 20 gwei
530
+ });
531
+ // Returns: string (hex-encoded signed transaction)
532
+ ```
533
+
502
534
  #### sendTransaction(transaction)
503
535
 
504
536
  Send an Ethereum transaction.
@@ -518,8 +550,8 @@ const result = await sdk.ethereum.sendTransaction({
518
550
  Switch to a different Ethereum chain.
519
551
 
520
552
  ```typescript
521
- await sdk.ethereum.switchChain(1); // Ethereum mainnet
522
- await sdk.ethereum.switchChain(137); // Polygon
553
+ await sdk.ethereum.switchChain(1); // Ethereum mainnet
554
+ await sdk.ethereum.switchChain(137); // Polygon
523
555
  await sdk.ethereum.switchChain(42161); // Arbitrum One
524
556
  ```
525
557
 
@@ -571,10 +603,10 @@ import { NetworkId } from "@phantom/browser-sdk";
571
603
 
572
604
  // Enable auto-confirm for specific chains
573
605
  const result = await sdk.enableAutoConfirm({
574
- chains: [NetworkId.SOLANA_MAINNET, NetworkId.ETHEREUM_MAINNET]
606
+ chains: [NetworkId.SOLANA_MAINNET, NetworkId.ETHEREUM_MAINNET],
575
607
  });
576
608
 
577
- // Enable auto-confirm for all supported chains
609
+ // Enable auto-confirm for all supported chains
578
610
  const result = await sdk.enableAutoConfirm();
579
611
 
580
612
  console.log("Auto-confirm enabled:", result.enabled);
@@ -619,29 +651,29 @@ console.log("Supported chains:", supportedChains.chains);
619
651
  import { NetworkId } from "@phantom/browser-sdk";
620
652
 
621
653
  // Solana networks
622
- NetworkId.SOLANA_MAINNET // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
623
- NetworkId.SOLANA_DEVNET // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
624
- NetworkId.SOLANA_TESTNET // "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
654
+ NetworkId.SOLANA_MAINNET; // "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
655
+ NetworkId.SOLANA_DEVNET; // "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
656
+ NetworkId.SOLANA_TESTNET; // "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
625
657
 
626
658
  // Ethereum networks
627
- NetworkId.ETHEREUM_MAINNET // "eip155:1"
628
- NetworkId.ETHEREUM_SEPOLIA // "eip155:11155111"
659
+ NetworkId.ETHEREUM_MAINNET; // "eip155:1"
660
+ NetworkId.ETHEREUM_SEPOLIA; // "eip155:11155111"
629
661
 
630
- // Polygon networks
631
- NetworkId.POLYGON_MAINNET // "eip155:137"
632
- NetworkId.POLYGON_AMOY // "eip155:80002"
662
+ // Polygon networks
663
+ NetworkId.POLYGON_MAINNET; // "eip155:137"
664
+ NetworkId.POLYGON_AMOY; // "eip155:80002"
633
665
 
634
666
  // Arbitrum networks
635
- NetworkId.ARBITRUM_ONE // "eip155:42161"
636
- NetworkId.ARBITRUM_SEPOLIA // "eip155:421614"
667
+ NetworkId.ARBITRUM_ONE; // "eip155:42161"
668
+ NetworkId.ARBITRUM_SEPOLIA; // "eip155:421614"
637
669
 
638
670
  // Optimism networks
639
- NetworkId.OPTIMISM_MAINNET // "eip155:10"
640
- NetworkId.OPTIMISM_GOERLI // "eip155:420"
671
+ NetworkId.OPTIMISM_MAINNET; // "eip155:10"
672
+ NetworkId.OPTIMISM_GOERLI; // "eip155:420"
641
673
 
642
674
  // Base networks
643
- NetworkId.BASE_MAINNET // "eip155:8453"
644
- NetworkId.BASE_SEPOLIA // "eip155:84532"
675
+ NetworkId.BASE_MAINNET; // "eip155:8453"
676
+ NetworkId.BASE_SEPOLIA; // "eip155:84532"
645
677
  ```
646
678
 
647
679
  **Important Notes:**
@@ -661,14 +693,14 @@ The BrowserSDK provides dynamic debug configuration that can be changed at runti
661
693
  // Enable debug logging
662
694
  sdk.enableDebug();
663
695
 
664
- // Disable debug logging
696
+ // Disable debug logging
665
697
  sdk.disableDebug();
666
698
 
667
699
  // Set debug level
668
700
  sdk.setDebugLevel(DebugLevel.INFO);
669
701
 
670
702
  // Set debug callback function
671
- sdk.setDebugCallback((message) => {
703
+ sdk.setDebugCallback(message => {
672
704
  console.log(`[${message.category}] ${message.message}`, message.data);
673
705
  });
674
706
 
@@ -676,10 +708,10 @@ sdk.setDebugCallback((message) => {
676
708
  sdk.configureDebug({
677
709
  enabled: true,
678
710
  level: DebugLevel.DEBUG,
679
- callback: (message) => {
711
+ callback: message => {
680
712
  // Handle debug messages
681
713
  console.log(`[${message.level}] ${message.category}: ${message.message}`);
682
- }
714
+ },
683
715
  });
684
716
  ```
685
717
 
@@ -689,10 +721,10 @@ sdk.configureDebug({
689
721
  import { DebugLevel } from "@phantom/browser-sdk";
690
722
 
691
723
  // 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)
724
+ DebugLevel.ERROR; // 0 - Only error messages
725
+ DebugLevel.WARN; // 1 - Warning and error messages
726
+ DebugLevel.INFO; // 2 - Info, warning, and error messages
727
+ DebugLevel.DEBUG; // 3 - All debug messages (most verbose)
696
728
  ```
697
729
 
698
730
  ### Debug Message Structure
@@ -701,11 +733,11 @@ Debug callbacks receive a `DebugMessage` object:
701
733
 
702
734
  ```typescript
703
735
  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)
736
+ timestamp: number; // Unix timestamp
737
+ level: DebugLevel; // Message level
738
+ category: string; // Component category (e.g., "BrowserSDK", "ProviderManager")
739
+ message: string; // Debug message text
740
+ data?: any; // Additional debug data (optional)
709
741
  }
710
742
  ```
711
743
 
@@ -726,17 +758,17 @@ const debugMessages: DebugMessage[] = [];
726
758
  sdk.configureDebug({
727
759
  enabled: true,
728
760
  level: DebugLevel.INFO,
729
- callback: (message) => {
761
+ callback: message => {
730
762
  debugMessages.push(message);
731
-
763
+
732
764
  // Keep only last 100 messages
733
765
  if (debugMessages.length > 100) {
734
766
  debugMessages.shift();
735
767
  }
736
-
768
+
737
769
  // Update UI
738
770
  updateDebugConsole();
739
- }
771
+ },
740
772
  });
741
773
 
742
774
  // Dynamic debug level changing
@@ -835,7 +867,7 @@ import {
835
867
  import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
836
868
 
837
869
  const sdk = new BrowserSDK({
838
- providerType: "injected",
870
+ providerType: "injected",
839
871
  addressTypes: [AddressType.solana],
840
872
  solanaProvider: "kit",
841
873
  });
@@ -926,4 +958,3 @@ const result = await sdk.ethereum.sendTransaction({
926
958
  maxPriorityFeePerGas: parseGwei("2").toString(),
927
959
  });
928
960
  ```
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 };