@phantom/browser-sdk 1.0.0-beta.6 → 1.0.0-beta.8

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/dist/index.d.ts CHANGED
@@ -52,29 +52,51 @@ 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
- interface BrowserSDKConfig extends Partial<Omit<EmbeddedProviderConfig, "authOptions">> {
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";
67
82
  authOptions?: {
68
83
  authUrl?: string;
69
84
  redirectUrl?: string;
70
85
  };
71
86
  }
87
+ interface ExtendedInjectedProviderConfig extends InjectedProviderConfig {
88
+ providerType: "injected";
89
+ appId?: never;
90
+ authOptions?: never;
91
+ embeddedWalletType?: never;
92
+ }
72
93
 
73
94
  interface Provider {
74
95
  connect(authOptions?: AuthOptions): Promise<ConnectResult>;
75
96
  disconnect(): Promise<void>;
76
97
  getAddresses(): WalletAddress[];
77
98
  isConnected(): boolean;
99
+ autoConnect(): Promise<void>;
78
100
  solana: ISolanaChain;
79
101
  ethereum: IEthereumChain;
80
102
  }
package/dist/index.js CHANGED
@@ -547,6 +547,87 @@ var InjectedProvider = class {
547
547
  });
548
548
  debug.info(DebugCategory.INJECTED_PROVIDER, "Injected provider disconnected successfully");
549
549
  }
550
+ /**
551
+ * Attempt auto-connection using onlyIfTrusted parameter
552
+ * This will only connect if the dApp is already trusted by the user
553
+ * Should be called after setting up event listeners
554
+ */
555
+ async autoConnect() {
556
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting auto-connect with onlyIfTrusted=true");
557
+ this.emit("connect_start", {
558
+ source: "auto-connect",
559
+ providerType: "injected"
560
+ });
561
+ try {
562
+ if (!this.phantom.extension?.isInstalled?.()) {
563
+ debug.warn(DebugCategory.INJECTED_PROVIDER, "Phantom wallet extension not found for auto-connect");
564
+ this.emit("connect_error", {
565
+ error: "Phantom wallet not found",
566
+ source: "auto-connect"
567
+ });
568
+ return;
569
+ }
570
+ const connectedAddresses = [];
571
+ if (this.addressTypes.includes(import_client4.AddressType.solana)) {
572
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting Solana auto-connect");
573
+ try {
574
+ const publicKey = await this.phantom.solana.connect({ onlyIfTrusted: true });
575
+ if (publicKey) {
576
+ connectedAddresses.push({
577
+ addressType: import_client4.AddressType.solana,
578
+ address: publicKey
579
+ });
580
+ debug.info(DebugCategory.INJECTED_PROVIDER, "Solana auto-connected successfully", { address: publicKey });
581
+ }
582
+ } catch (err) {
583
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Solana auto-connect failed (expected if not trusted)", { error: err });
584
+ }
585
+ }
586
+ if (this.addressTypes.includes(import_client4.AddressType.ethereum)) {
587
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting Ethereum auto-connect");
588
+ try {
589
+ const accounts = await this.phantom.ethereum.connect({ onlyIfTrusted: true });
590
+ if (accounts && accounts.length > 0) {
591
+ connectedAddresses.push(
592
+ ...accounts.map((address) => ({
593
+ addressType: import_client4.AddressType.ethereum,
594
+ address
595
+ }))
596
+ );
597
+ debug.info(DebugCategory.INJECTED_PROVIDER, "Ethereum auto-connected successfully", { addresses: accounts });
598
+ }
599
+ } catch (err) {
600
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum auto-connect failed (expected if not trusted)", { error: err });
601
+ }
602
+ }
603
+ if (connectedAddresses.length === 0) {
604
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Auto-connect failed: no trusted connections available");
605
+ this.emit("connect_error", {
606
+ error: "No trusted connections available",
607
+ source: "auto-connect"
608
+ });
609
+ return;
610
+ }
611
+ this.addresses = connectedAddresses;
612
+ this.connected = true;
613
+ this.emit("connect", {
614
+ addresses: this.addresses,
615
+ source: "auto-connect"
616
+ });
617
+ debug.info(DebugCategory.INJECTED_PROVIDER, "Auto-connect successful", {
618
+ addressCount: connectedAddresses.length,
619
+ addresses: connectedAddresses.map((addr) => ({ type: addr.addressType, address: addr.address.substring(0, 8) + "..." }))
620
+ });
621
+ } catch (error) {
622
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Auto-connect failed with error", {
623
+ error: error instanceof Error ? error.message : String(error)
624
+ });
625
+ this.emit("connect_error", {
626
+ error: error instanceof Error ? error.message : "Auto-connect failed",
627
+ source: "auto-connect"
628
+ });
629
+ }
630
+ }
550
631
  getAddresses() {
551
632
  return this.addresses;
552
633
  }
@@ -634,7 +715,7 @@ var InjectedProvider = class {
634
715
  const handleSolanaDisconnect = () => {
635
716
  debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnect event received");
636
717
  this.addresses = this.addresses.filter((addr) => addr.addressType !== import_client4.AddressType.solana);
637
- this.connected = this.addresses.length > 0;
718
+ this.connected = false;
638
719
  this.emit("disconnect", {
639
720
  source: "injected-extension"
640
721
  });
@@ -654,10 +735,7 @@ var InjectedProvider = class {
654
735
  };
655
736
  const cleanupConnect = this.phantom.solana.addEventListener("connect", handleSolanaConnect);
656
737
  const cleanupDisconnect = this.phantom.solana.addEventListener("disconnect", handleSolanaDisconnect);
657
- const cleanupAccountChanged = this.phantom.solana.addEventListener(
658
- "accountChanged",
659
- handleSolanaAccountChanged
660
- );
738
+ const cleanupAccountChanged = this.phantom.solana.addEventListener("accountChanged", handleSolanaAccountChanged);
661
739
  this.browserInjectedCleanupFunctions.push(cleanupConnect, cleanupDisconnect, cleanupAccountChanged);
662
740
  }
663
741
  setupEthereumEvents() {
@@ -682,7 +760,7 @@ var InjectedProvider = class {
682
760
  const handleEthereumDisconnect = () => {
683
761
  debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received");
684
762
  this.addresses = this.addresses.filter((addr) => addr.addressType !== import_client4.AddressType.ethereum);
685
- this.connected = this.addresses.length > 0;
763
+ this.connected = false;
686
764
  this.emit("disconnect", {
687
765
  source: "injected-extension"
688
766
  });
@@ -697,11 +775,16 @@ var InjectedProvider = class {
697
775
  address
698
776
  }))
699
777
  );
778
+ this.emit("connect", {
779
+ addresses: this.addresses,
780
+ source: "injected-extension-account-change"
781
+ });
782
+ } else {
783
+ this.connected = false;
784
+ this.emit("disconnect", {
785
+ source: "injected-extension-account-change"
786
+ });
700
787
  }
701
- this.emit("connect", {
702
- addresses: this.addresses,
703
- source: "injected-extension-account-change"
704
- });
705
788
  };
706
789
  const cleanupConnect = this.phantom.ethereum.addEventListener("connect", handleEthereumConnect);
707
790
  const cleanupDisconnect = this.phantom.ethereum.addEventListener("disconnect", handleEthereumDisconnect);
@@ -863,7 +946,8 @@ var BrowserAuthProvider = class {
863
946
  app_id: phantomOptions.appId,
864
947
  redirect_uri: phantomOptions.redirectUrl || (typeof window !== "undefined" ? this.getValidatedCurrentUrl() : ""),
865
948
  session_id: phantomOptions.sessionId,
866
- clear_previous_session: true.toString()
949
+ clear_previous_session: true.toString(),
950
+ sdk_version: "1.0.0-beta.8"
867
951
  });
868
952
  if (phantomOptions.provider) {
869
953
  debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Provider specified, will skip selection", {
@@ -1141,7 +1225,7 @@ var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvi
1141
1225
  // Full user agent for more detailed info
1142
1226
  [import_constants2.ANALYTICS_HEADERS.APP_ID]: config.appId,
1143
1227
  [import_constants2.ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
1144
- [import_constants2.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.6"
1228
+ [import_constants2.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.8"
1145
1229
  // Replaced at build time
1146
1230
  }
1147
1231
  };
@@ -1615,7 +1699,7 @@ var BrowserSDK = class {
1615
1699
  async autoConnect() {
1616
1700
  debug.log(DebugCategory.BROWSER_SDK, "Attempting auto-connect");
1617
1701
  const currentProvider = this.providerManager.getCurrentProvider();
1618
- if (currentProvider && "autoConnect" in currentProvider) {
1702
+ if (currentProvider) {
1619
1703
  await currentProvider.autoConnect();
1620
1704
  } else {
1621
1705
  debug.warn(DebugCategory.BROWSER_SDK, "Current provider does not support auto-connect", {
package/dist/index.mjs CHANGED
@@ -511,6 +511,87 @@ var InjectedProvider = class {
511
511
  });
512
512
  debug.info(DebugCategory.INJECTED_PROVIDER, "Injected provider disconnected successfully");
513
513
  }
514
+ /**
515
+ * Attempt auto-connection using onlyIfTrusted parameter
516
+ * This will only connect if the dApp is already trusted by the user
517
+ * Should be called after setting up event listeners
518
+ */
519
+ async autoConnect() {
520
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting auto-connect with onlyIfTrusted=true");
521
+ this.emit("connect_start", {
522
+ source: "auto-connect",
523
+ providerType: "injected"
524
+ });
525
+ try {
526
+ if (!this.phantom.extension?.isInstalled?.()) {
527
+ debug.warn(DebugCategory.INJECTED_PROVIDER, "Phantom wallet extension not found for auto-connect");
528
+ this.emit("connect_error", {
529
+ error: "Phantom wallet not found",
530
+ source: "auto-connect"
531
+ });
532
+ return;
533
+ }
534
+ const connectedAddresses = [];
535
+ if (this.addressTypes.includes(AddressType4.solana)) {
536
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting Solana auto-connect");
537
+ try {
538
+ const publicKey = await this.phantom.solana.connect({ onlyIfTrusted: true });
539
+ if (publicKey) {
540
+ connectedAddresses.push({
541
+ addressType: AddressType4.solana,
542
+ address: publicKey
543
+ });
544
+ debug.info(DebugCategory.INJECTED_PROVIDER, "Solana auto-connected successfully", { address: publicKey });
545
+ }
546
+ } catch (err) {
547
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Solana auto-connect failed (expected if not trusted)", { error: err });
548
+ }
549
+ }
550
+ if (this.addressTypes.includes(AddressType4.ethereum)) {
551
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting Ethereum auto-connect");
552
+ try {
553
+ const accounts = await this.phantom.ethereum.connect({ onlyIfTrusted: true });
554
+ if (accounts && accounts.length > 0) {
555
+ connectedAddresses.push(
556
+ ...accounts.map((address) => ({
557
+ addressType: AddressType4.ethereum,
558
+ address
559
+ }))
560
+ );
561
+ debug.info(DebugCategory.INJECTED_PROVIDER, "Ethereum auto-connected successfully", { addresses: accounts });
562
+ }
563
+ } catch (err) {
564
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum auto-connect failed (expected if not trusted)", { error: err });
565
+ }
566
+ }
567
+ if (connectedAddresses.length === 0) {
568
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Auto-connect failed: no trusted connections available");
569
+ this.emit("connect_error", {
570
+ error: "No trusted connections available",
571
+ source: "auto-connect"
572
+ });
573
+ return;
574
+ }
575
+ this.addresses = connectedAddresses;
576
+ this.connected = true;
577
+ this.emit("connect", {
578
+ addresses: this.addresses,
579
+ source: "auto-connect"
580
+ });
581
+ debug.info(DebugCategory.INJECTED_PROVIDER, "Auto-connect successful", {
582
+ addressCount: connectedAddresses.length,
583
+ addresses: connectedAddresses.map((addr) => ({ type: addr.addressType, address: addr.address.substring(0, 8) + "..." }))
584
+ });
585
+ } catch (error) {
586
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Auto-connect failed with error", {
587
+ error: error instanceof Error ? error.message : String(error)
588
+ });
589
+ this.emit("connect_error", {
590
+ error: error instanceof Error ? error.message : "Auto-connect failed",
591
+ source: "auto-connect"
592
+ });
593
+ }
594
+ }
514
595
  getAddresses() {
515
596
  return this.addresses;
516
597
  }
@@ -598,7 +679,7 @@ var InjectedProvider = class {
598
679
  const handleSolanaDisconnect = () => {
599
680
  debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnect event received");
600
681
  this.addresses = this.addresses.filter((addr) => addr.addressType !== AddressType4.solana);
601
- this.connected = this.addresses.length > 0;
682
+ this.connected = false;
602
683
  this.emit("disconnect", {
603
684
  source: "injected-extension"
604
685
  });
@@ -618,10 +699,7 @@ var InjectedProvider = class {
618
699
  };
619
700
  const cleanupConnect = this.phantom.solana.addEventListener("connect", handleSolanaConnect);
620
701
  const cleanupDisconnect = this.phantom.solana.addEventListener("disconnect", handleSolanaDisconnect);
621
- const cleanupAccountChanged = this.phantom.solana.addEventListener(
622
- "accountChanged",
623
- handleSolanaAccountChanged
624
- );
702
+ const cleanupAccountChanged = this.phantom.solana.addEventListener("accountChanged", handleSolanaAccountChanged);
625
703
  this.browserInjectedCleanupFunctions.push(cleanupConnect, cleanupDisconnect, cleanupAccountChanged);
626
704
  }
627
705
  setupEthereumEvents() {
@@ -646,7 +724,7 @@ var InjectedProvider = class {
646
724
  const handleEthereumDisconnect = () => {
647
725
  debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received");
648
726
  this.addresses = this.addresses.filter((addr) => addr.addressType !== AddressType4.ethereum);
649
- this.connected = this.addresses.length > 0;
727
+ this.connected = false;
650
728
  this.emit("disconnect", {
651
729
  source: "injected-extension"
652
730
  });
@@ -661,11 +739,16 @@ var InjectedProvider = class {
661
739
  address
662
740
  }))
663
741
  );
742
+ this.emit("connect", {
743
+ addresses: this.addresses,
744
+ source: "injected-extension-account-change"
745
+ });
746
+ } else {
747
+ this.connected = false;
748
+ this.emit("disconnect", {
749
+ source: "injected-extension-account-change"
750
+ });
664
751
  }
665
- this.emit("connect", {
666
- addresses: this.addresses,
667
- source: "injected-extension-account-change"
668
- });
669
752
  };
670
753
  const cleanupConnect = this.phantom.ethereum.addEventListener("connect", handleEthereumConnect);
671
754
  const cleanupDisconnect = this.phantom.ethereum.addEventListener("disconnect", handleEthereumDisconnect);
@@ -827,7 +910,8 @@ var BrowserAuthProvider = class {
827
910
  app_id: phantomOptions.appId,
828
911
  redirect_uri: phantomOptions.redirectUrl || (typeof window !== "undefined" ? this.getValidatedCurrentUrl() : ""),
829
912
  session_id: phantomOptions.sessionId,
830
- clear_previous_session: true.toString()
913
+ clear_previous_session: true.toString(),
914
+ sdk_version: "1.0.0-beta.8"
831
915
  });
832
916
  if (phantomOptions.provider) {
833
917
  debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Provider specified, will skip selection", {
@@ -1105,7 +1189,7 @@ var EmbeddedProvider = class extends CoreEmbeddedProvider {
1105
1189
  // Full user agent for more detailed info
1106
1190
  [ANALYTICS_HEADERS.APP_ID]: config.appId,
1107
1191
  [ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
1108
- [ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.6"
1192
+ [ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.8"
1109
1193
  // Replaced at build time
1110
1194
  }
1111
1195
  };
@@ -1579,7 +1663,7 @@ var BrowserSDK = class {
1579
1663
  async autoConnect() {
1580
1664
  debug.log(DebugCategory.BROWSER_SDK, "Attempting auto-connect");
1581
1665
  const currentProvider = this.providerManager.getCurrentProvider();
1582
- if (currentProvider && "autoConnect" in currentProvider) {
1666
+ if (currentProvider) {
1583
1667
  await currentProvider.autoConnect();
1584
1668
  } else {
1585
1669
  debug.warn(DebugCategory.BROWSER_SDK, "Current provider does not support auto-connect", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/browser-sdk",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
4
4
  "description": "Browser SDK for Phantom Wallet",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,11 +29,11 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@phantom/base64url": "^1.0.0-beta.6",
32
- "@phantom/browser-injected-sdk": "^1.0.0-beta.3",
32
+ "@phantom/browser-injected-sdk": "^1.0.0-beta.5",
33
33
  "@phantom/chain-interfaces": "^1.0.0-beta.6",
34
- "@phantom/client": "^1.0.0-beta.6",
34
+ "@phantom/client": "^1.0.0-beta.8",
35
35
  "@phantom/constants": "^1.0.0-beta.6",
36
- "@phantom/embedded-provider-core": "^1.0.0-beta.6",
36
+ "@phantom/embedded-provider-core": "^1.0.0-beta.8",
37
37
  "@phantom/indexed-db-stamper": "^1.0.0-beta.1",
38
38
  "@phantom/parsers": "^1.0.0-beta.6",
39
39
  "@phantom/sdk-types": "^1.0.0-beta.6",