@phantom/browser-sdk 1.0.2 → 1.0.3
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 +9 -15
- package/dist/index.d.ts +3 -3
- package/dist/index.js +218 -173
- package/dist/index.mjs +196 -151
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -30,11 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
AddressType: () =>
|
|
33
|
+
AddressType: () => import_client5.AddressType,
|
|
34
34
|
BrowserSDK: () => BrowserSDK,
|
|
35
35
|
DebugCategory: () => DebugCategory,
|
|
36
36
|
DebugLevel: () => DebugLevel,
|
|
37
|
-
NetworkId: () =>
|
|
37
|
+
NetworkId: () => import_constants7.NetworkId,
|
|
38
|
+
PHANTOM_ICON: () => import_constants8.PHANTOM_ICON,
|
|
38
39
|
debug: () => debug,
|
|
39
40
|
detectBrowser: () => detectBrowser,
|
|
40
41
|
getBrowserDisplayName: () => getBrowserDisplayName,
|
|
@@ -51,7 +52,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
51
52
|
var import_client = require("@phantom/client");
|
|
52
53
|
|
|
53
54
|
// src/providers/injected/index.ts
|
|
54
|
-
var
|
|
55
|
+
var import_client4 = require("@phantom/client");
|
|
55
56
|
|
|
56
57
|
// src/debug.ts
|
|
57
58
|
var DebugLevel = /* @__PURE__ */ ((DebugLevel2) => {
|
|
@@ -128,12 +129,27 @@ var DebugCategory = {
|
|
|
128
129
|
};
|
|
129
130
|
|
|
130
131
|
// src/wallets/discovery.ts
|
|
131
|
-
var
|
|
132
|
+
var import_constants = require("@phantom/constants");
|
|
133
|
+
var import_client3 = require("@phantom/client");
|
|
132
134
|
var import_browser_injected_sdk = require("@phantom/browser-injected-sdk");
|
|
133
135
|
var import_browser_injected_sdk2 = require("@phantom/browser-injected-sdk");
|
|
134
136
|
var import_solana = require("@phantom/browser-injected-sdk/solana");
|
|
135
137
|
var import_ethereum = require("@phantom/browser-injected-sdk/ethereum");
|
|
136
138
|
var import_auto_confirm = require("@phantom/browser-injected-sdk/auto-confirm");
|
|
139
|
+
|
|
140
|
+
// src/wallets/custom-wallets.ts
|
|
141
|
+
var import_client2 = require("@phantom/client");
|
|
142
|
+
var CUSTOM_WALLET_CONFIGS = [
|
|
143
|
+
{
|
|
144
|
+
id: "coinbase-wallet",
|
|
145
|
+
name: "Coinbase Wallet",
|
|
146
|
+
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNTYiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTI4IDU2YzE1LjQ2NCAwIDI4LTEyLjUzNiAyOC0yOFM0My40NjQgMCAyOCAwIDAgMTIuNTM2IDAgMjhzMTIuNTM2IDI4IDI4IDI4WiIgZmlsbD0iIzFCNTNFNCIvPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNyAyOGMwIDExLjU5OCA5LjQwMiAyMSAyMSAyMXMyMS05LjQwMiAyMS0yMVMzOS41OTggNyAyOCA3IDcgMTYuNDAyIDcgMjhabTE3LjIzNC02Ljc2NmEzIDMgMCAwIDAtMyAzdjcuNTMzYTMgMyAwIDAgMCAzIDNoNy41MzNhMyAzIDAgMCAwIDMtM3YtNy41MzNhMyAzIDAgMCAwLTMtM2gtNy41MzNaIiBmaWxsPSIjZmZmIi8+PC9zdmc+",
|
|
147
|
+
windowProperty: "coinbaseSolana",
|
|
148
|
+
addressTypes: [import_client2.AddressType.solana]
|
|
149
|
+
}
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
// src/wallets/discovery.ts
|
|
137
153
|
function generateWalletIdFromEIP6963(info) {
|
|
138
154
|
if (info.rdns) {
|
|
139
155
|
return info.rdns.split(".").reverse().join("-");
|
|
@@ -166,7 +182,7 @@ function processEIP6963Providers(providers) {
|
|
|
166
182
|
id: walletId,
|
|
167
183
|
name: info.name,
|
|
168
184
|
icon: info.icon,
|
|
169
|
-
addressTypes: [
|
|
185
|
+
addressTypes: [import_client3.AddressType.ethereum],
|
|
170
186
|
providers: {
|
|
171
187
|
// EIP-6963 provider implements EIP-1193 interface (IEthereumChain)
|
|
172
188
|
ethereum: provider
|
|
@@ -376,7 +392,7 @@ async function discoverSolanaWallets() {
|
|
|
376
392
|
id: walletId,
|
|
377
393
|
name: wallet.name,
|
|
378
394
|
icon: wallet.icon,
|
|
379
|
-
addressTypes: [
|
|
395
|
+
addressTypes: [import_client3.AddressType.solana],
|
|
380
396
|
providers: {
|
|
381
397
|
// Cast to ISolanaChain - Wallet Standard wallets have compatible methods
|
|
382
398
|
// The InjectedWalletSolanaChain wrapper will handle the actual method calls
|
|
@@ -397,6 +413,51 @@ async function discoverSolanaWallets() {
|
|
|
397
413
|
walletNames: wallets.map((w) => w.name)
|
|
398
414
|
};
|
|
399
415
|
debug.log(DebugCategory.BROWSER_SDK, "Wallet Standard Solana discovery completed", finalLogData);
|
|
416
|
+
const customWallets = discoverCustomSolanaWallets();
|
|
417
|
+
wallets.push(...customWallets);
|
|
418
|
+
return wallets;
|
|
419
|
+
}
|
|
420
|
+
function discoverCustomSolanaWallets() {
|
|
421
|
+
const wallets = [];
|
|
422
|
+
if (typeof window === "undefined") {
|
|
423
|
+
debug.log(DebugCategory.BROWSER_SDK, "Custom wallet discovery skipped (not in browser environment)");
|
|
424
|
+
return wallets;
|
|
425
|
+
}
|
|
426
|
+
debug.log(DebugCategory.BROWSER_SDK, "Starting custom Solana wallet discovery", {
|
|
427
|
+
configCount: CUSTOM_WALLET_CONFIGS.length
|
|
428
|
+
});
|
|
429
|
+
for (const config of CUSTOM_WALLET_CONFIGS) {
|
|
430
|
+
if (!config.addressTypes.includes(import_client3.AddressType.solana)) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
const provider = window[config.windowProperty];
|
|
434
|
+
if (!provider) {
|
|
435
|
+
debug.log(DebugCategory.BROWSER_SDK, "Custom wallet not found", {
|
|
436
|
+
walletId: config.id,
|
|
437
|
+
windowProperty: config.windowProperty
|
|
438
|
+
});
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
debug.log(DebugCategory.BROWSER_SDK, "Discovered custom Solana wallet", {
|
|
442
|
+
walletId: config.id,
|
|
443
|
+
walletName: config.name,
|
|
444
|
+
windowProperty: config.windowProperty
|
|
445
|
+
});
|
|
446
|
+
wallets.push({
|
|
447
|
+
id: config.id,
|
|
448
|
+
name: config.name,
|
|
449
|
+
icon: config.icon,
|
|
450
|
+
addressTypes: config.addressTypes,
|
|
451
|
+
providers: {
|
|
452
|
+
solana: provider
|
|
453
|
+
},
|
|
454
|
+
discovery: "custom"
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
debug.log(DebugCategory.BROWSER_SDK, "Custom Solana wallet discovery completed", {
|
|
458
|
+
discoveredCount: wallets.length,
|
|
459
|
+
walletIds: wallets.map((w) => w.id)
|
|
460
|
+
});
|
|
400
461
|
return wallets;
|
|
401
462
|
}
|
|
402
463
|
function discoverPhantomWallet(addressTypes) {
|
|
@@ -407,10 +468,10 @@ function discoverPhantomWallet(addressTypes) {
|
|
|
407
468
|
return null;
|
|
408
469
|
}
|
|
409
470
|
const plugins = [(0, import_browser_injected_sdk2.createExtensionPlugin)()];
|
|
410
|
-
if (addressTypes.includes(
|
|
471
|
+
if (addressTypes.includes(import_client3.AddressType.solana)) {
|
|
411
472
|
plugins.push((0, import_solana.createSolanaPlugin)());
|
|
412
473
|
}
|
|
413
|
-
if (addressTypes.includes(
|
|
474
|
+
if (addressTypes.includes(import_client3.AddressType.ethereum)) {
|
|
414
475
|
plugins.push((0, import_ethereum.createEthereumPlugin)());
|
|
415
476
|
}
|
|
416
477
|
plugins.push((0, import_auto_confirm.createAutoConfirmPlugin)());
|
|
@@ -418,12 +479,11 @@ function discoverPhantomWallet(addressTypes) {
|
|
|
418
479
|
return {
|
|
419
480
|
id: "phantom",
|
|
420
481
|
name: "Phantom",
|
|
421
|
-
icon:
|
|
422
|
-
// Icon will be rendered from icons package in UI components
|
|
482
|
+
icon: import_constants.PHANTOM_ICON,
|
|
423
483
|
addressTypes,
|
|
424
484
|
providers: {
|
|
425
|
-
solana: addressTypes.includes(
|
|
426
|
-
ethereum: addressTypes.includes(
|
|
485
|
+
solana: addressTypes.includes(import_client3.AddressType.solana) ? phantomInstance.solana : void 0,
|
|
486
|
+
ethereum: addressTypes.includes(import_client3.AddressType.ethereum) ? phantomInstance.ethereum : void 0
|
|
427
487
|
},
|
|
428
488
|
isPhantom: true,
|
|
429
489
|
phantomInstance,
|
|
@@ -488,6 +548,9 @@ async function discoverWallets(addressTypes) {
|
|
|
488
548
|
return Array.from(walletMap.values());
|
|
489
549
|
}
|
|
490
550
|
|
|
551
|
+
// src/wallets/registry.ts
|
|
552
|
+
var import_constants2 = require("@phantom/constants");
|
|
553
|
+
|
|
491
554
|
// src/providers/injected/chains/InjectedWalletSolanaChain.ts
|
|
492
555
|
var import_eventemitter3 = require("eventemitter3");
|
|
493
556
|
var import_buffer = require("buffer");
|
|
@@ -495,61 +558,55 @@ var InjectedWalletSolanaChain = class {
|
|
|
495
558
|
constructor(provider, walletId, walletName) {
|
|
496
559
|
// Expose eventEmitter for testing - allows tests to trigger events directly
|
|
497
560
|
this.eventEmitter = new import_eventemitter3.EventEmitter();
|
|
498
|
-
this._connected = false;
|
|
499
561
|
this._publicKey = null;
|
|
500
562
|
this.provider = provider;
|
|
501
563
|
this.walletId = walletId;
|
|
502
564
|
this.walletName = walletName;
|
|
503
565
|
this.setupEventListeners();
|
|
504
566
|
}
|
|
505
|
-
get connected() {
|
|
506
|
-
return this._connected;
|
|
507
|
-
}
|
|
508
567
|
get publicKey() {
|
|
509
568
|
return this._publicKey;
|
|
510
569
|
}
|
|
570
|
+
get isConnected() {
|
|
571
|
+
return this.provider.isConnected || !!this._publicKey;
|
|
572
|
+
}
|
|
511
573
|
async connect(options) {
|
|
512
|
-
debug.log(DebugCategory.INJECTED_PROVIDER, "External wallet Solana connect", {
|
|
513
|
-
walletId: this.walletId,
|
|
514
|
-
walletName: this.walletName,
|
|
515
|
-
onlyIfTrusted: options?.onlyIfTrusted
|
|
516
|
-
});
|
|
517
574
|
try {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
debug.info(DebugCategory.INJECTED_PROVIDER, "External wallet Solana connected", {
|
|
575
|
+
await this.provider.connect(options);
|
|
576
|
+
const isConnected = this.provider.isConnected;
|
|
577
|
+
if (!isConnected || this.provider.publicKey === null) {
|
|
578
|
+
debug.error(DebugCategory.INJECTED_PROVIDER, "Provider not connected after connect() call", {
|
|
523
579
|
walletId: this.walletId,
|
|
524
580
|
walletName: this.walletName,
|
|
525
|
-
|
|
581
|
+
providerConnected: isConnected,
|
|
582
|
+
providerPublicKey: this.provider.publicKey
|
|
526
583
|
});
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
584
|
+
throw new Error("Provider not connected after connect() call");
|
|
585
|
+
}
|
|
586
|
+
let publicKey;
|
|
587
|
+
const providerPublicKey = this.provider.publicKey;
|
|
588
|
+
if (typeof providerPublicKey === "string") {
|
|
589
|
+
publicKey = providerPublicKey;
|
|
590
|
+
} else if (providerPublicKey !== null && providerPublicKey !== void 0 && typeof providerPublicKey.toString === "function") {
|
|
591
|
+
publicKey = providerPublicKey.toString();
|
|
592
|
+
} else {
|
|
593
|
+
debug.error(DebugCategory.INJECTED_PROVIDER, "Invalid publicKey format in provider state", {
|
|
533
594
|
walletId: this.walletId,
|
|
534
595
|
walletName: this.walletName,
|
|
535
|
-
|
|
596
|
+
publicKeyType: typeof providerPublicKey
|
|
536
597
|
});
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
if (Array.isArray(result) && result.length > 0) {
|
|
540
|
-
const firstAccount = result[0];
|
|
541
|
-
if (typeof firstAccount === "object" && firstAccount !== null && "address" in firstAccount) {
|
|
542
|
-
this._connected = true;
|
|
543
|
-
this._publicKey = firstAccount.address;
|
|
544
|
-
debug.info(DebugCategory.INJECTED_PROVIDER, "External wallet Solana connected", {
|
|
545
|
-
walletId: this.walletId,
|
|
546
|
-
walletName: this.walletName,
|
|
547
|
-
publicKey: firstAccount.address
|
|
548
|
-
});
|
|
549
|
-
return { publicKey: firstAccount.address };
|
|
550
|
-
}
|
|
598
|
+
throw new Error("Invalid publicKey format in provider state");
|
|
551
599
|
}
|
|
552
|
-
|
|
600
|
+
if (!publicKey || publicKey.length === 0) {
|
|
601
|
+
throw new Error("Empty publicKey from provider");
|
|
602
|
+
}
|
|
603
|
+
this._publicKey = publicKey;
|
|
604
|
+
debug.info(DebugCategory.INJECTED_PROVIDER, "External wallet Solana connected", {
|
|
605
|
+
walletId: this.walletId,
|
|
606
|
+
walletName: this.walletName,
|
|
607
|
+
publicKey
|
|
608
|
+
});
|
|
609
|
+
return { publicKey };
|
|
553
610
|
} catch (error) {
|
|
554
611
|
debug.error(DebugCategory.INJECTED_PROVIDER, "External wallet Solana connect failed", {
|
|
555
612
|
walletId: this.walletId,
|
|
@@ -566,7 +623,6 @@ var InjectedWalletSolanaChain = class {
|
|
|
566
623
|
});
|
|
567
624
|
try {
|
|
568
625
|
await this.provider.disconnect();
|
|
569
|
-
this._connected = false;
|
|
570
626
|
this._publicKey = null;
|
|
571
627
|
debug.info(DebugCategory.INJECTED_PROVIDER, "External wallet Solana disconnected", {
|
|
572
628
|
walletId: this.walletId,
|
|
@@ -702,28 +758,19 @@ var InjectedWalletSolanaChain = class {
|
|
|
702
758
|
switchNetwork(_network) {
|
|
703
759
|
return Promise.resolve();
|
|
704
760
|
}
|
|
705
|
-
getPublicKey() {
|
|
706
|
-
return Promise.resolve(this._publicKey);
|
|
707
|
-
}
|
|
708
|
-
isConnected() {
|
|
709
|
-
return this._connected;
|
|
710
|
-
}
|
|
711
761
|
setupEventListeners() {
|
|
712
762
|
if (typeof this.provider.on === "function") {
|
|
713
763
|
this.provider.on("connect", (publicKey) => {
|
|
714
|
-
this._connected = true;
|
|
715
764
|
this._publicKey = publicKey;
|
|
716
765
|
this.eventEmitter.emit("connect", publicKey);
|
|
717
766
|
});
|
|
718
767
|
this.provider.on("disconnect", () => {
|
|
719
|
-
this._connected = false;
|
|
720
768
|
this._publicKey = null;
|
|
721
769
|
this.eventEmitter.emit("disconnect");
|
|
722
770
|
});
|
|
723
771
|
this.provider.on("accountChanged", (publicKey) => {
|
|
724
|
-
this._publicKey = publicKey;
|
|
725
|
-
this.
|
|
726
|
-
this.eventEmitter.emit("accountChanged", publicKey);
|
|
772
|
+
this._publicKey = publicKey ? publicKey : null;
|
|
773
|
+
this.eventEmitter.emit("accountChanged", this._publicKey);
|
|
727
774
|
});
|
|
728
775
|
}
|
|
729
776
|
}
|
|
@@ -749,12 +796,12 @@ var WalletStandardSolanaAdapter = class {
|
|
|
749
796
|
this.walletName = walletName;
|
|
750
797
|
this.setupEventListeners();
|
|
751
798
|
}
|
|
752
|
-
get connected() {
|
|
753
|
-
return this._publicKey !== null;
|
|
754
|
-
}
|
|
755
799
|
get publicKey() {
|
|
756
800
|
return this._publicKey;
|
|
757
801
|
}
|
|
802
|
+
get isConnected() {
|
|
803
|
+
return this._publicKey !== null;
|
|
804
|
+
}
|
|
758
805
|
async connect(_options) {
|
|
759
806
|
try {
|
|
760
807
|
const connectFeature = this.wallet.features["standard:connect"];
|
|
@@ -966,12 +1013,6 @@ var WalletStandardSolanaAdapter = class {
|
|
|
966
1013
|
async switchNetwork(_network) {
|
|
967
1014
|
return Promise.resolve();
|
|
968
1015
|
}
|
|
969
|
-
getPublicKey() {
|
|
970
|
-
return Promise.resolve(this._publicKey);
|
|
971
|
-
}
|
|
972
|
-
isConnected() {
|
|
973
|
-
return this._publicKey !== null;
|
|
974
|
-
}
|
|
975
1016
|
/**
|
|
976
1017
|
* Set up event listeners for Wallet Standard events
|
|
977
1018
|
* Maps Wallet Standard "change" events to "accountChanged" events
|
|
@@ -1106,9 +1147,6 @@ var InjectedWalletEthereumChain = class {
|
|
|
1106
1147
|
this.walletName = walletName;
|
|
1107
1148
|
this.setupEventListeners();
|
|
1108
1149
|
}
|
|
1109
|
-
get connected() {
|
|
1110
|
-
return this._connected;
|
|
1111
|
-
}
|
|
1112
1150
|
get chainId() {
|
|
1113
1151
|
return this._chainId;
|
|
1114
1152
|
}
|
|
@@ -1238,7 +1276,8 @@ var InjectedWalletEthereumChain = class {
|
|
|
1238
1276
|
address
|
|
1239
1277
|
});
|
|
1240
1278
|
try {
|
|
1241
|
-
const
|
|
1279
|
+
const providerAny = this.provider;
|
|
1280
|
+
const providerConnected = (typeof providerAny.isConnected === "function" ? providerAny.isConnected() : false) || (typeof providerAny.connected === "boolean" ? providerAny.connected : false);
|
|
1242
1281
|
if (!this._connected || this._accounts.length === 0 || !providerConnected) {
|
|
1243
1282
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Not connected, attempting to connect before signing", {
|
|
1244
1283
|
walletId: this.walletId,
|
|
@@ -1552,8 +1591,7 @@ var InjectedWalletRegistry = class {
|
|
|
1552
1591
|
const phantomWallet = {
|
|
1553
1592
|
id: "phantom",
|
|
1554
1593
|
name: "Phantom",
|
|
1555
|
-
icon:
|
|
1556
|
-
// Icon will be rendered from icons package in UI components
|
|
1594
|
+
icon: import_constants2.PHANTOM_ICON,
|
|
1557
1595
|
addressTypes,
|
|
1558
1596
|
providers: wrappedProviders,
|
|
1559
1597
|
isPhantom: true,
|
|
@@ -1699,13 +1737,13 @@ var InjectedProvider = class {
|
|
|
1699
1737
|
return provider;
|
|
1700
1738
|
}
|
|
1701
1739
|
get solana() {
|
|
1702
|
-
return this.getChainProvider(
|
|
1740
|
+
return this.getChainProvider(import_client4.AddressType.solana, "solana", "Solana");
|
|
1703
1741
|
}
|
|
1704
1742
|
/**
|
|
1705
1743
|
* Access to Ethereum chain operations
|
|
1706
1744
|
*/
|
|
1707
1745
|
get ethereum() {
|
|
1708
|
-
return this.getChainProvider(
|
|
1746
|
+
return this.getChainProvider(import_client4.AddressType.ethereum, "ethereum", "Ethereum");
|
|
1709
1747
|
}
|
|
1710
1748
|
validateAndSelectWallet(requestedWalletId) {
|
|
1711
1749
|
if (!this.walletRegistry.has(requestedWalletId)) {
|
|
@@ -1746,7 +1784,7 @@ var InjectedProvider = class {
|
|
|
1746
1784
|
this.setupEventListeners(walletInfo);
|
|
1747
1785
|
}
|
|
1748
1786
|
const connectedAddresses = [];
|
|
1749
|
-
if (this.addressTypes.includes(
|
|
1787
|
+
if (this.addressTypes.includes(import_client4.AddressType.solana) && walletInfo.providers?.solana) {
|
|
1750
1788
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting Solana connection", {
|
|
1751
1789
|
walletId: this.selectedWalletId,
|
|
1752
1790
|
walletName: walletInfo.name,
|
|
@@ -1758,7 +1796,7 @@ var InjectedProvider = class {
|
|
|
1758
1796
|
);
|
|
1759
1797
|
const address = result.publicKey;
|
|
1760
1798
|
connectedAddresses.push({
|
|
1761
|
-
addressType:
|
|
1799
|
+
addressType: import_client4.AddressType.solana,
|
|
1762
1800
|
address
|
|
1763
1801
|
});
|
|
1764
1802
|
debug.info(DebugCategory.INJECTED_PROVIDER, "Solana connected successfully", {
|
|
@@ -1779,7 +1817,7 @@ var InjectedProvider = class {
|
|
|
1779
1817
|
throw err;
|
|
1780
1818
|
}
|
|
1781
1819
|
}
|
|
1782
|
-
if (this.addressTypes.includes(
|
|
1820
|
+
if (this.addressTypes.includes(import_client4.AddressType.ethereum) && walletInfo.providers?.ethereum) {
|
|
1783
1821
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting Ethereum connection", {
|
|
1784
1822
|
walletId: this.selectedWalletId,
|
|
1785
1823
|
walletName: walletInfo.name,
|
|
@@ -1795,7 +1833,7 @@ var InjectedProvider = class {
|
|
|
1795
1833
|
if (accounts.length > 0) {
|
|
1796
1834
|
connectedAddresses.push(
|
|
1797
1835
|
...accounts.map((address) => ({
|
|
1798
|
-
addressType:
|
|
1836
|
+
addressType: import_client4.AddressType.ethereum,
|
|
1799
1837
|
address
|
|
1800
1838
|
}))
|
|
1801
1839
|
);
|
|
@@ -1875,7 +1913,8 @@ var InjectedProvider = class {
|
|
|
1875
1913
|
this.emit("connect", {
|
|
1876
1914
|
addresses: connectedAddresses,
|
|
1877
1915
|
source: "manual-connect",
|
|
1878
|
-
authUserId
|
|
1916
|
+
authUserId,
|
|
1917
|
+
walletId
|
|
1879
1918
|
});
|
|
1880
1919
|
return result;
|
|
1881
1920
|
}
|
|
@@ -1887,12 +1926,13 @@ var InjectedProvider = class {
|
|
|
1887
1926
|
if (authOptions.provider !== "injected") {
|
|
1888
1927
|
throw new Error(`Invalid provider for injected connection: ${authOptions.provider}. Must be "injected"`);
|
|
1889
1928
|
}
|
|
1929
|
+
const requestedWalletId = authOptions.walletId || "phantom";
|
|
1890
1930
|
this.emit("connect_start", {
|
|
1891
1931
|
source: "manual-connect",
|
|
1892
|
-
providerType: "injected"
|
|
1932
|
+
providerType: "injected",
|
|
1933
|
+
walletId: requestedWalletId
|
|
1893
1934
|
});
|
|
1894
1935
|
try {
|
|
1895
|
-
const requestedWalletId = authOptions.walletId || "phantom";
|
|
1896
1936
|
const walletInfo = this.validateAndSelectWallet(requestedWalletId);
|
|
1897
1937
|
const connectedAddresses = await this.connectToWallet(walletInfo);
|
|
1898
1938
|
return await this.finalizeConnection(connectedAddresses, "injected", this.selectedWalletId || void 0);
|
|
@@ -1908,7 +1948,7 @@ var InjectedProvider = class {
|
|
|
1908
1948
|
debug.info(DebugCategory.INJECTED_PROVIDER, "Starting injected provider disconnect");
|
|
1909
1949
|
const walletInfo = this.walletRegistry.getById(this.selectedWalletId || "phantom");
|
|
1910
1950
|
if (walletInfo?.providers) {
|
|
1911
|
-
if (this.addressTypes.includes(
|
|
1951
|
+
if (this.addressTypes.includes(import_client4.AddressType.solana) && walletInfo.providers.solana) {
|
|
1912
1952
|
try {
|
|
1913
1953
|
await walletInfo.providers.solana.disconnect();
|
|
1914
1954
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnected successfully");
|
|
@@ -1916,7 +1956,7 @@ var InjectedProvider = class {
|
|
|
1916
1956
|
debug.warn(DebugCategory.INJECTED_PROVIDER, "Failed to disconnect Solana", { error: err });
|
|
1917
1957
|
}
|
|
1918
1958
|
}
|
|
1919
|
-
if (this.addressTypes.includes(
|
|
1959
|
+
if (this.addressTypes.includes(import_client4.AddressType.ethereum) && walletInfo.providers.ethereum) {
|
|
1920
1960
|
try {
|
|
1921
1961
|
await walletInfo.providers.ethereum.disconnect();
|
|
1922
1962
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnected successfully");
|
|
@@ -2012,7 +2052,8 @@ var InjectedProvider = class {
|
|
|
2012
2052
|
this.emit("connect", {
|
|
2013
2053
|
addresses: connectedAddresses,
|
|
2014
2054
|
source: "auto-connect",
|
|
2015
|
-
authUserId
|
|
2055
|
+
authUserId,
|
|
2056
|
+
walletId: this.selectedWalletId
|
|
2016
2057
|
});
|
|
2017
2058
|
debug.info(DebugCategory.INJECTED_PROVIDER, "Auto-connect successful", {
|
|
2018
2059
|
addressCount: connectedAddresses.length,
|
|
@@ -2073,12 +2114,13 @@ var InjectedProvider = class {
|
|
|
2073
2114
|
createSolanaConnectHandler(walletId, source) {
|
|
2074
2115
|
return async (publicKey) => {
|
|
2075
2116
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana connect event received", { publicKey, walletId });
|
|
2076
|
-
const newAddresses = this.updateWalletAddresses(walletId, [publicKey],
|
|
2117
|
+
const newAddresses = this.updateWalletAddresses(walletId, [publicKey], import_client4.AddressType.solana);
|
|
2077
2118
|
const authUserId = await this.getAuthUserId("Solana connect event");
|
|
2078
2119
|
this.emit("connect", {
|
|
2079
2120
|
addresses: newAddresses,
|
|
2080
2121
|
source,
|
|
2081
|
-
authUserId
|
|
2122
|
+
authUserId,
|
|
2123
|
+
walletId: this.selectedWalletId
|
|
2082
2124
|
});
|
|
2083
2125
|
};
|
|
2084
2126
|
}
|
|
@@ -2089,7 +2131,7 @@ var InjectedProvider = class {
|
|
|
2089
2131
|
return () => {
|
|
2090
2132
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnect event received", { walletId });
|
|
2091
2133
|
const state = this.getWalletState(walletId);
|
|
2092
|
-
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !==
|
|
2134
|
+
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== import_client4.AddressType.solana);
|
|
2093
2135
|
this.setWalletState(walletId, {
|
|
2094
2136
|
connected: filteredAddresses.length > 0,
|
|
2095
2137
|
addresses: filteredAddresses
|
|
@@ -2107,16 +2149,17 @@ var InjectedProvider = class {
|
|
|
2107
2149
|
return async (publicKey) => {
|
|
2108
2150
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Solana account changed event received", { publicKey, walletId });
|
|
2109
2151
|
if (publicKey) {
|
|
2110
|
-
const newAddresses = this.updateWalletAddresses(walletId, [publicKey],
|
|
2152
|
+
const newAddresses = this.updateWalletAddresses(walletId, [publicKey], import_client4.AddressType.solana);
|
|
2111
2153
|
const authUserId = await this.getAuthUserId("Solana account changed event");
|
|
2112
2154
|
this.emit("connect", {
|
|
2113
2155
|
addresses: newAddresses,
|
|
2114
2156
|
source: this.getAccountChangeSource(source),
|
|
2115
|
-
authUserId
|
|
2157
|
+
authUserId,
|
|
2158
|
+
walletId: this.selectedWalletId
|
|
2116
2159
|
});
|
|
2117
2160
|
} else {
|
|
2118
2161
|
const state = this.getWalletState(walletId);
|
|
2119
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !==
|
|
2162
|
+
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== import_client4.AddressType.solana);
|
|
2120
2163
|
this.setWalletState(walletId, {
|
|
2121
2164
|
connected: otherAddresses.length > 0,
|
|
2122
2165
|
addresses: otherAddresses
|
|
@@ -2148,12 +2191,13 @@ var InjectedProvider = class {
|
|
|
2148
2191
|
}
|
|
2149
2192
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum connect event received", { accounts, walletId });
|
|
2150
2193
|
if (accounts.length > 0) {
|
|
2151
|
-
const newAddresses = this.updateWalletAddresses(walletId, accounts,
|
|
2194
|
+
const newAddresses = this.updateWalletAddresses(walletId, accounts, import_client4.AddressType.ethereum);
|
|
2152
2195
|
const authUserId = await this.getAuthUserId("Ethereum connect event");
|
|
2153
2196
|
this.emit("connect", {
|
|
2154
2197
|
addresses: newAddresses,
|
|
2155
2198
|
source,
|
|
2156
|
-
authUserId
|
|
2199
|
+
authUserId,
|
|
2200
|
+
walletId: this.selectedWalletId
|
|
2157
2201
|
});
|
|
2158
2202
|
}
|
|
2159
2203
|
};
|
|
@@ -2165,7 +2209,7 @@ var InjectedProvider = class {
|
|
|
2165
2209
|
return () => {
|
|
2166
2210
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received", { walletId });
|
|
2167
2211
|
const state = this.getWalletState(walletId);
|
|
2168
|
-
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !==
|
|
2212
|
+
const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== import_client4.AddressType.ethereum);
|
|
2169
2213
|
this.setWalletState(walletId, {
|
|
2170
2214
|
connected: filteredAddresses.length > 0,
|
|
2171
2215
|
addresses: filteredAddresses
|
|
@@ -2182,16 +2226,17 @@ var InjectedProvider = class {
|
|
|
2182
2226
|
return async (accounts) => {
|
|
2183
2227
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum accounts changed event received", { accounts, walletId });
|
|
2184
2228
|
if (accounts && accounts.length > 0) {
|
|
2185
|
-
const newAddresses = this.updateWalletAddresses(walletId, accounts,
|
|
2229
|
+
const newAddresses = this.updateWalletAddresses(walletId, accounts, import_client4.AddressType.ethereum);
|
|
2186
2230
|
const authUserId = await this.getAuthUserId("Ethereum accounts changed event");
|
|
2187
2231
|
this.emit("connect", {
|
|
2188
2232
|
addresses: newAddresses,
|
|
2189
2233
|
source: this.getAccountChangeSource(source),
|
|
2190
|
-
authUserId
|
|
2234
|
+
authUserId,
|
|
2235
|
+
walletId: this.selectedWalletId
|
|
2191
2236
|
});
|
|
2192
2237
|
} else {
|
|
2193
2238
|
const state = this.getWalletState(walletId);
|
|
2194
|
-
const otherAddresses = state.addresses.filter((addr) => addr.addressType !==
|
|
2239
|
+
const otherAddresses = state.addresses.filter((addr) => addr.addressType !== import_client4.AddressType.ethereum);
|
|
2195
2240
|
this.setWalletState(walletId, {
|
|
2196
2241
|
connected: otherAddresses.length > 0,
|
|
2197
2242
|
addresses: otherAddresses
|
|
@@ -2385,7 +2430,9 @@ var InjectedProvider = class {
|
|
|
2385
2430
|
this.eventListenerCleanups.set(walletId, [...existingCleanups, ...cleanups]);
|
|
2386
2431
|
}
|
|
2387
2432
|
/**
|
|
2388
|
-
* Unified event listener setup for all wallet types (Phantom and external)
|
|
2433
|
+
* Unified event listener setup for all wallet types (Phantom and external).
|
|
2434
|
+
* Cleans up listeners for previously selected wallets to prevent stale events
|
|
2435
|
+
* from causing walletId flicker during connections.
|
|
2389
2436
|
*/
|
|
2390
2437
|
setupEventListeners(walletInfo) {
|
|
2391
2438
|
const walletId = this.selectedWalletId || "phantom";
|
|
@@ -2393,11 +2440,22 @@ var InjectedProvider = class {
|
|
|
2393
2440
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Event listeners already set up for wallet", { walletId });
|
|
2394
2441
|
return;
|
|
2395
2442
|
}
|
|
2443
|
+
for (const existingWalletId of this.eventListenersSetup) {
|
|
2444
|
+
if (existingWalletId === walletId) {
|
|
2445
|
+
continue;
|
|
2446
|
+
}
|
|
2447
|
+
const cleanups = this.eventListenerCleanups.get(existingWalletId);
|
|
2448
|
+
if (cleanups) {
|
|
2449
|
+
debug.log(DebugCategory.INJECTED_PROVIDER, "Cleaning up event listeners for wallet", { existingWalletId });
|
|
2450
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
2451
|
+
}
|
|
2452
|
+
this.eventListenersSetup.delete(existingWalletId);
|
|
2453
|
+
}
|
|
2396
2454
|
debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up event listeners", { walletId });
|
|
2397
|
-
if (this.addressTypes.includes(
|
|
2455
|
+
if (this.addressTypes.includes(import_client4.AddressType.solana) && walletInfo.providers?.solana) {
|
|
2398
2456
|
this.setupSolanaEventListeners(walletInfo.providers.solana, walletId, "wallet");
|
|
2399
2457
|
}
|
|
2400
|
-
if (this.addressTypes.includes(
|
|
2458
|
+
if (this.addressTypes.includes(import_client4.AddressType.ethereum) && walletInfo.providers?.ethereum) {
|
|
2401
2459
|
this.setupEthereumEventListeners(walletInfo.providers.ethereum, walletId, "wallet");
|
|
2402
2460
|
}
|
|
2403
2461
|
this.eventListenersSetup.add(walletId);
|
|
@@ -2541,7 +2599,7 @@ var BrowserURLParamsAccessor = class {
|
|
|
2541
2599
|
var browserUrlParamsAccessor = new BrowserURLParamsAccessor();
|
|
2542
2600
|
|
|
2543
2601
|
// src/providers/embedded/adapters/auth.ts
|
|
2544
|
-
var
|
|
2602
|
+
var import_constants3 = require("@phantom/constants");
|
|
2545
2603
|
|
|
2546
2604
|
// src/utils/browser-detection.ts
|
|
2547
2605
|
function parseBrowserFromUserAgent(userAgent, hasBraveAPI) {
|
|
@@ -2706,7 +2764,7 @@ var BrowserAuthProvider = class {
|
|
|
2706
2764
|
provider: phantomOptions.provider,
|
|
2707
2765
|
authUrl: phantomOptions.authUrl
|
|
2708
2766
|
});
|
|
2709
|
-
const baseUrl = phantomOptions.authUrl ||
|
|
2767
|
+
const baseUrl = phantomOptions.authUrl || import_constants3.DEFAULT_AUTH_URL;
|
|
2710
2768
|
debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Using auth URL", { baseUrl });
|
|
2711
2769
|
const params = new URLSearchParams({
|
|
2712
2770
|
public_key: phantomOptions.publicKey,
|
|
@@ -2716,9 +2774,10 @@ var BrowserAuthProvider = class {
|
|
|
2716
2774
|
// OAuth session management - defaults to allow refresh unless explicitly clearing after logout
|
|
2717
2775
|
clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
|
|
2718
2776
|
allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
|
|
2719
|
-
sdk_version: "1.0.
|
|
2777
|
+
sdk_version: "1.0.3",
|
|
2720
2778
|
sdk_type: "browser",
|
|
2721
|
-
platform: detectBrowser().name
|
|
2779
|
+
platform: detectBrowser().name,
|
|
2780
|
+
algorithm: phantomOptions.algorithm || import_constants3.DEFAULT_AUTHENTICATOR_ALGORITHM
|
|
2722
2781
|
});
|
|
2723
2782
|
if (phantomOptions.provider) {
|
|
2724
2783
|
debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Provider specified, will skip selection", {
|
|
@@ -2839,28 +2898,9 @@ var BrowserAuthProvider = class {
|
|
|
2839
2898
|
// src/providers/embedded/adapters/phantom-app.ts
|
|
2840
2899
|
var import_browser_injected_sdk4 = require("@phantom/browser-injected-sdk");
|
|
2841
2900
|
|
|
2842
|
-
// src/
|
|
2901
|
+
// src/waitForPhantomExtension.ts
|
|
2843
2902
|
var import_browser_injected_sdk3 = require("@phantom/browser-injected-sdk");
|
|
2844
|
-
async function
|
|
2845
|
-
const extensionInstalled = await waitForExtension(timeoutMs);
|
|
2846
|
-
if (!extensionInstalled) {
|
|
2847
|
-
return false;
|
|
2848
|
-
}
|
|
2849
|
-
try {
|
|
2850
|
-
if (!window.phantom?.app?.features || typeof window.phantom.app.features !== "function") {
|
|
2851
|
-
return false;
|
|
2852
|
-
}
|
|
2853
|
-
const response = await window.phantom.app.features();
|
|
2854
|
-
if (!Array.isArray(response.features)) {
|
|
2855
|
-
return false;
|
|
2856
|
-
}
|
|
2857
|
-
return response.features.includes("phantom_login");
|
|
2858
|
-
} catch (error) {
|
|
2859
|
-
console.error("Error checking Phantom extension features", error);
|
|
2860
|
-
return false;
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2863
|
-
async function waitForExtension(timeoutMs) {
|
|
2903
|
+
async function waitForPhantomExtension(timeoutMs = 3e3) {
|
|
2864
2904
|
return new Promise((resolve) => {
|
|
2865
2905
|
const startTime = Date.now();
|
|
2866
2906
|
const checkInterval = 100;
|
|
@@ -2883,6 +2923,27 @@ async function waitForExtension(timeoutMs) {
|
|
|
2883
2923
|
});
|
|
2884
2924
|
}
|
|
2885
2925
|
|
|
2926
|
+
// src/isPhantomLoginAvailable.ts
|
|
2927
|
+
async function isPhantomLoginAvailable(timeoutMs = 3e3) {
|
|
2928
|
+
const extensionInstalled = await waitForPhantomExtension(timeoutMs);
|
|
2929
|
+
if (!extensionInstalled) {
|
|
2930
|
+
return false;
|
|
2931
|
+
}
|
|
2932
|
+
try {
|
|
2933
|
+
if (!window.phantom?.app?.features || typeof window.phantom.app.features !== "function") {
|
|
2934
|
+
return false;
|
|
2935
|
+
}
|
|
2936
|
+
const response = await window.phantom.app.features();
|
|
2937
|
+
if (!Array.isArray(response.features)) {
|
|
2938
|
+
return false;
|
|
2939
|
+
}
|
|
2940
|
+
return response.features.includes("phantom_login");
|
|
2941
|
+
} catch (error) {
|
|
2942
|
+
console.error("Error checking Phantom extension features", error);
|
|
2943
|
+
return false;
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
|
|
2886
2947
|
// src/providers/embedded/adapters/phantom-app.ts
|
|
2887
2948
|
var BrowserPhantomAppProvider = class {
|
|
2888
2949
|
/**
|
|
@@ -2952,7 +3013,7 @@ var BrowserLogger = class {
|
|
|
2952
3013
|
};
|
|
2953
3014
|
|
|
2954
3015
|
// src/providers/embedded/index.ts
|
|
2955
|
-
var
|
|
3016
|
+
var import_constants4 = require("@phantom/constants");
|
|
2956
3017
|
var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvider {
|
|
2957
3018
|
constructor(config) {
|
|
2958
3019
|
debug.log(DebugCategory.EMBEDDED_PROVIDER, "Initializing Browser EmbeddedProvider", { config });
|
|
@@ -2973,14 +3034,14 @@ var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvi
|
|
|
2973
3034
|
name: platformName,
|
|
2974
3035
|
// Use detected browser name and version for identification
|
|
2975
3036
|
analyticsHeaders: {
|
|
2976
|
-
[
|
|
2977
|
-
[
|
|
3037
|
+
[import_constants4.ANALYTICS_HEADERS.SDK_TYPE]: "browser",
|
|
3038
|
+
[import_constants4.ANALYTICS_HEADERS.PLATFORM]: browserName,
|
|
2978
3039
|
// firefox, chrome, safari, etc.
|
|
2979
|
-
[
|
|
3040
|
+
[import_constants4.ANALYTICS_HEADERS.PLATFORM_VERSION]: version,
|
|
2980
3041
|
// Full user agent for more detailed info
|
|
2981
|
-
[
|
|
2982
|
-
[
|
|
2983
|
-
[
|
|
3042
|
+
[import_constants4.ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
3043
|
+
[import_constants4.ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
3044
|
+
[import_constants4.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.3"
|
|
2984
3045
|
// Replaced at build time
|
|
2985
3046
|
}
|
|
2986
3047
|
};
|
|
@@ -2997,7 +3058,7 @@ var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvi
|
|
|
2997
3058
|
|
|
2998
3059
|
// src/ProviderManager.ts
|
|
2999
3060
|
var import_embedded_provider_core2 = require("@phantom/embedded-provider-core");
|
|
3000
|
-
var
|
|
3061
|
+
var import_constants5 = require("@phantom/constants");
|
|
3001
3062
|
|
|
3002
3063
|
// src/utils/auth-callback.ts
|
|
3003
3064
|
function isAuthFailureCallback(searchParams) {
|
|
@@ -3017,11 +3078,12 @@ function isAuthCallbackUrl(searchParams) {
|
|
|
3017
3078
|
}
|
|
3018
3079
|
|
|
3019
3080
|
// src/utils/deeplink.ts
|
|
3020
|
-
function getDeeplinkToPhantom(ref) {
|
|
3021
|
-
|
|
3081
|
+
function getDeeplinkToPhantom(ref, currentHref) {
|
|
3082
|
+
const resolvedHref = currentHref ?? window.location.href;
|
|
3083
|
+
if (!resolvedHref.startsWith("http:") && !resolvedHref.startsWith("https:")) {
|
|
3022
3084
|
throw new Error("Invalid URL protocol - only HTTP/HTTPS URLs are supported for deeplinks");
|
|
3023
3085
|
}
|
|
3024
|
-
const currentUrl = encodeURIComponent(
|
|
3086
|
+
const currentUrl = encodeURIComponent(resolvedHref);
|
|
3025
3087
|
const refParam = ref ? `?ref=${encodeURIComponent(ref)}` : "";
|
|
3026
3088
|
return `https://phantom.app/ul/browse/${currentUrl}${refParam}`;
|
|
3027
3089
|
}
|
|
@@ -3117,8 +3179,14 @@ var ProviderManager = class {
|
|
|
3117
3179
|
} else if (requestedProvider === "deeplink") {
|
|
3118
3180
|
try {
|
|
3119
3181
|
const deeplinkUrl = getDeeplinkToPhantom();
|
|
3120
|
-
if (typeof window !== "undefined") {
|
|
3121
|
-
|
|
3182
|
+
if (typeof window !== "undefined" && window.location) {
|
|
3183
|
+
try {
|
|
3184
|
+
window.location.href = deeplinkUrl;
|
|
3185
|
+
} catch (error) {
|
|
3186
|
+
debug.warn(DebugCategory.PROVIDER_MANAGER, "Failed to set deeplink location", {
|
|
3187
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3188
|
+
});
|
|
3189
|
+
}
|
|
3122
3190
|
}
|
|
3123
3191
|
return {
|
|
3124
3192
|
addresses: [],
|
|
@@ -3381,8 +3449,8 @@ var ProviderManager = class {
|
|
|
3381
3449
|
if (!this.config.appId) {
|
|
3382
3450
|
throw new Error("appId is required for embedded provider");
|
|
3383
3451
|
}
|
|
3384
|
-
const apiBaseUrl = this.config.apiBaseUrl ||
|
|
3385
|
-
const authUrl = this.config.authOptions?.authUrl ||
|
|
3452
|
+
const apiBaseUrl = this.config.apiBaseUrl || import_constants5.DEFAULT_WALLET_API_URL;
|
|
3453
|
+
const authUrl = this.config.authOptions?.authUrl || import_constants5.DEFAULT_AUTH_URL;
|
|
3386
3454
|
provider = new EmbeddedProvider({
|
|
3387
3455
|
apiBaseUrl,
|
|
3388
3456
|
appId: this.config.appId,
|
|
@@ -3391,7 +3459,7 @@ var ProviderManager = class {
|
|
|
3391
3459
|
authUrl,
|
|
3392
3460
|
redirectUrl: this.config.authOptions?.redirectUrl || this.getValidatedCurrentUrl()
|
|
3393
3461
|
},
|
|
3394
|
-
embeddedWalletType: embeddedWalletType ||
|
|
3462
|
+
embeddedWalletType: embeddedWalletType || import_constants5.DEFAULT_EMBEDDED_WALLET_TYPE,
|
|
3395
3463
|
addressTypes: this.config.addressTypes || [import_client.AddressType.solana]
|
|
3396
3464
|
});
|
|
3397
3465
|
} else {
|
|
@@ -3427,7 +3495,7 @@ var ProviderManager = class {
|
|
|
3427
3495
|
|
|
3428
3496
|
// src/BrowserSDK.ts
|
|
3429
3497
|
var import_embedded_provider_core3 = require("@phantom/embedded-provider-core");
|
|
3430
|
-
var
|
|
3498
|
+
var import_constants6 = require("@phantom/constants");
|
|
3431
3499
|
var BROWSER_SDK_PROVIDER_TYPES = [
|
|
3432
3500
|
...import_embedded_provider_core3.EMBEDDED_PROVIDER_AUTH_TYPES,
|
|
3433
3501
|
"injected",
|
|
@@ -3463,7 +3531,7 @@ var BrowserSDK = class {
|
|
|
3463
3531
|
});
|
|
3464
3532
|
throw new Error("appId is required when using embedded providers (google, apple, phantom, etc.)");
|
|
3465
3533
|
}
|
|
3466
|
-
const embeddedWalletType = config.embeddedWalletType ||
|
|
3534
|
+
const embeddedWalletType = config.embeddedWalletType || import_constants6.DEFAULT_EMBEDDED_WALLET_TYPE;
|
|
3467
3535
|
if (!["app-wallet", "user-wallet"].includes(embeddedWalletType)) {
|
|
3468
3536
|
debug.error(DebugCategory.BROWSER_SDK, "Invalid embeddedWalletType", {
|
|
3469
3537
|
embeddedWalletType: config.embeddedWalletType
|
|
@@ -3589,6 +3657,7 @@ var BrowserSDK = class {
|
|
|
3589
3657
|
*/
|
|
3590
3658
|
async autoConnect() {
|
|
3591
3659
|
debug.log(DebugCategory.BROWSER_SDK, "Attempting auto-connect with fallback strategy");
|
|
3660
|
+
await this.discoverWallets();
|
|
3592
3661
|
const result = await this.providerManager.autoConnect();
|
|
3593
3662
|
if (result) {
|
|
3594
3663
|
debug.info(DebugCategory.BROWSER_SDK, "Auto-connect successful", {
|
|
@@ -3736,31 +3805,7 @@ var BrowserSDK = class {
|
|
|
3736
3805
|
}
|
|
3737
3806
|
};
|
|
3738
3807
|
|
|
3739
|
-
// src/waitForPhantomExtension.ts
|
|
3740
|
-
var import_browser_injected_sdk5 = require("@phantom/browser-injected-sdk");
|
|
3741
|
-
async function waitForPhantomExtension(timeoutMs = 3e3) {
|
|
3742
|
-
return new Promise((resolve) => {
|
|
3743
|
-
const startTime = Date.now();
|
|
3744
|
-
const checkInterval = 100;
|
|
3745
|
-
const checkForExtension = () => {
|
|
3746
|
-
try {
|
|
3747
|
-
if ((0, import_browser_injected_sdk5.isPhantomExtensionInstalled)()) {
|
|
3748
|
-
resolve(true);
|
|
3749
|
-
return;
|
|
3750
|
-
}
|
|
3751
|
-
} catch (error) {
|
|
3752
|
-
}
|
|
3753
|
-
const elapsed = Date.now() - startTime;
|
|
3754
|
-
if (elapsed >= timeoutMs) {
|
|
3755
|
-
resolve(false);
|
|
3756
|
-
return;
|
|
3757
|
-
}
|
|
3758
|
-
setTimeout(checkForExtension, checkInterval);
|
|
3759
|
-
};
|
|
3760
|
-
checkForExtension();
|
|
3761
|
-
});
|
|
3762
|
-
}
|
|
3763
|
-
|
|
3764
3808
|
// src/index.ts
|
|
3765
|
-
var
|
|
3766
|
-
var
|
|
3809
|
+
var import_constants7 = require("@phantom/constants");
|
|
3810
|
+
var import_client5 = require("@phantom/client");
|
|
3811
|
+
var import_constants8 = require("@phantom/constants");
|