@phantom/browser-sdk 1.0.0-beta.7 → 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 +1 -0
- package/dist/index.js +87 -6
- package/dist/index.mjs +87 -6
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
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 =
|
|
718
|
+
this.connected = false;
|
|
638
719
|
this.emit("disconnect", {
|
|
639
720
|
source: "injected-extension"
|
|
640
721
|
});
|
|
@@ -679,7 +760,7 @@ var InjectedProvider = class {
|
|
|
679
760
|
const handleEthereumDisconnect = () => {
|
|
680
761
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received");
|
|
681
762
|
this.addresses = this.addresses.filter((addr) => addr.addressType !== import_client4.AddressType.ethereum);
|
|
682
|
-
this.connected =
|
|
763
|
+
this.connected = false;
|
|
683
764
|
this.emit("disconnect", {
|
|
684
765
|
source: "injected-extension"
|
|
685
766
|
});
|
|
@@ -699,7 +780,7 @@ var InjectedProvider = class {
|
|
|
699
780
|
source: "injected-extension-account-change"
|
|
700
781
|
});
|
|
701
782
|
} else {
|
|
702
|
-
this.connected =
|
|
783
|
+
this.connected = false;
|
|
703
784
|
this.emit("disconnect", {
|
|
704
785
|
source: "injected-extension-account-change"
|
|
705
786
|
});
|
|
@@ -866,7 +947,7 @@ var BrowserAuthProvider = class {
|
|
|
866
947
|
redirect_uri: phantomOptions.redirectUrl || (typeof window !== "undefined" ? this.getValidatedCurrentUrl() : ""),
|
|
867
948
|
session_id: phantomOptions.sessionId,
|
|
868
949
|
clear_previous_session: true.toString(),
|
|
869
|
-
sdk_version: "1.0.0-beta.
|
|
950
|
+
sdk_version: "1.0.0-beta.8"
|
|
870
951
|
});
|
|
871
952
|
if (phantomOptions.provider) {
|
|
872
953
|
debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Provider specified, will skip selection", {
|
|
@@ -1144,7 +1225,7 @@ var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvi
|
|
|
1144
1225
|
// Full user agent for more detailed info
|
|
1145
1226
|
[import_constants2.ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
1146
1227
|
[import_constants2.ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
1147
|
-
[import_constants2.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.
|
|
1228
|
+
[import_constants2.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.8"
|
|
1148
1229
|
// Replaced at build time
|
|
1149
1230
|
}
|
|
1150
1231
|
};
|
|
@@ -1618,7 +1699,7 @@ var BrowserSDK = class {
|
|
|
1618
1699
|
async autoConnect() {
|
|
1619
1700
|
debug.log(DebugCategory.BROWSER_SDK, "Attempting auto-connect");
|
|
1620
1701
|
const currentProvider = this.providerManager.getCurrentProvider();
|
|
1621
|
-
if (currentProvider
|
|
1702
|
+
if (currentProvider) {
|
|
1622
1703
|
await currentProvider.autoConnect();
|
|
1623
1704
|
} else {
|
|
1624
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 =
|
|
682
|
+
this.connected = false;
|
|
602
683
|
this.emit("disconnect", {
|
|
603
684
|
source: "injected-extension"
|
|
604
685
|
});
|
|
@@ -643,7 +724,7 @@ var InjectedProvider = class {
|
|
|
643
724
|
const handleEthereumDisconnect = () => {
|
|
644
725
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received");
|
|
645
726
|
this.addresses = this.addresses.filter((addr) => addr.addressType !== AddressType4.ethereum);
|
|
646
|
-
this.connected =
|
|
727
|
+
this.connected = false;
|
|
647
728
|
this.emit("disconnect", {
|
|
648
729
|
source: "injected-extension"
|
|
649
730
|
});
|
|
@@ -663,7 +744,7 @@ var InjectedProvider = class {
|
|
|
663
744
|
source: "injected-extension-account-change"
|
|
664
745
|
});
|
|
665
746
|
} else {
|
|
666
|
-
this.connected =
|
|
747
|
+
this.connected = false;
|
|
667
748
|
this.emit("disconnect", {
|
|
668
749
|
source: "injected-extension-account-change"
|
|
669
750
|
});
|
|
@@ -830,7 +911,7 @@ var BrowserAuthProvider = class {
|
|
|
830
911
|
redirect_uri: phantomOptions.redirectUrl || (typeof window !== "undefined" ? this.getValidatedCurrentUrl() : ""),
|
|
831
912
|
session_id: phantomOptions.sessionId,
|
|
832
913
|
clear_previous_session: true.toString(),
|
|
833
|
-
sdk_version: "1.0.0-beta.
|
|
914
|
+
sdk_version: "1.0.0-beta.8"
|
|
834
915
|
});
|
|
835
916
|
if (phantomOptions.provider) {
|
|
836
917
|
debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Provider specified, will skip selection", {
|
|
@@ -1108,7 +1189,7 @@ var EmbeddedProvider = class extends CoreEmbeddedProvider {
|
|
|
1108
1189
|
// Full user agent for more detailed info
|
|
1109
1190
|
[ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
1110
1191
|
[ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
1111
|
-
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.
|
|
1192
|
+
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.8"
|
|
1112
1193
|
// Replaced at build time
|
|
1113
1194
|
}
|
|
1114
1195
|
};
|
|
@@ -1582,7 +1663,7 @@ var BrowserSDK = class {
|
|
|
1582
1663
|
async autoConnect() {
|
|
1583
1664
|
debug.log(DebugCategory.BROWSER_SDK, "Attempting auto-connect");
|
|
1584
1665
|
const currentProvider = this.providerManager.getCurrentProvider();
|
|
1585
|
-
if (currentProvider
|
|
1666
|
+
if (currentProvider) {
|
|
1586
1667
|
await currentProvider.autoConnect();
|
|
1587
1668
|
} else {
|
|
1588
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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",
|