@meshconnect/uwc-injected-connector 0.26.3 → 0.27.0
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/injected-connector.d.ts.map +1 -1
- package/dist/injected-connector.js +13 -3
- package/dist/injected-connector.js.map +1 -1
- package/dist/services/connection-manager.d.ts +3 -1
- package/dist/services/connection-manager.d.ts.map +1 -1
- package/dist/services/connection-manager.js +49 -21
- package/dist/services/connection-manager.js.map +1 -1
- package/dist/services/solana/solana-wallet-service.d.ts +19 -0
- package/dist/services/solana/solana-wallet-service.d.ts.map +1 -1
- package/dist/services/solana/solana-wallet-service.js +43 -0
- package/dist/services/solana/solana-wallet-service.js.map +1 -1
- package/package.json +6 -6
- package/src/injected-connector.test.ts +67 -0
- package/src/injected-connector.ts +18 -3
- package/src/services/connection-manager.test.ts +446 -0
- package/src/services/connection-manager.ts +84 -48
- package/src/services/solana/solana-wallet-service.silent-only.test.ts +162 -0
- package/src/services/solana/solana-wallet-service.ts +48 -0
|
@@ -196,6 +196,19 @@ export interface SecondarySolanaConnectGatheredInfo {
|
|
|
196
196
|
*/
|
|
197
197
|
const MAX_INJECTED_ID_LENGTH = 64
|
|
198
198
|
|
|
199
|
+
/**
|
|
200
|
+
* Whether a detected Solana wallet implements Wallet Standard `standard:connect`,
|
|
201
|
+
* i.e. whether its adapter's `autoConnect()` is a genuinely SILENT connect
|
|
202
|
+
* (`standard:connect` with `silent: true`). The legacy injected fallback
|
|
203
|
+
* (`LegacyInjectedSolanaWalletAdapter`) advertises no `standard:connect`, and
|
|
204
|
+
* its inherited `autoConnect()` is a plain, prompting `connect()`. Read from the
|
|
205
|
+
* marshalled `features` list rather than `instanceof`, so it holds for bridged
|
|
206
|
+
* (iframe) adapters too.
|
|
207
|
+
*/
|
|
208
|
+
function supportsStandardConnect(wallet: { features?: readonly string[] }) {
|
|
209
|
+
return wallet.features?.includes('standard:connect') === true
|
|
210
|
+
}
|
|
211
|
+
|
|
199
212
|
/**
|
|
200
213
|
* Does `address` satisfy the caller's pinned allow-list?
|
|
201
214
|
*
|
|
@@ -482,7 +495,8 @@ export class ConnectionManager {
|
|
|
482
495
|
async checkExistingConnections(
|
|
483
496
|
targetNamespace: Namespace,
|
|
484
497
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
485
|
-
requiredAddresses?: readonly string[]
|
|
498
|
+
requiredAddresses?: readonly string[],
|
|
499
|
+
options?: { silentOnly?: boolean }
|
|
486
500
|
): Promise<{
|
|
487
501
|
address: string | null
|
|
488
502
|
availableAddresses: AvailableAddress[]
|
|
@@ -494,6 +508,22 @@ export class ConnectionManager {
|
|
|
494
508
|
|
|
495
509
|
const availableAddresses: AvailableAddress[] = []
|
|
496
510
|
let currentAddress: string | null = null
|
|
511
|
+
// Silent-only (see `ConnectorConnectOptions.silentOnly`): every probe here
|
|
512
|
+
// must stay non-prompting. The secondary gathers normally fall back to a
|
|
513
|
+
// PROMPTING connect, so under silent-only they run only once the target is
|
|
514
|
+
// authorized, and then without those fallbacks.
|
|
515
|
+
const silentOnly = options?.silentOnly === true
|
|
516
|
+
const gatherOthers = async (
|
|
517
|
+
connectedNamespace: 'eip155' | 'solana' | 'tron' | 'tvm' | 'bip122'
|
|
518
|
+
): Promise<void> => {
|
|
519
|
+
if (silentOnly && !currentAddress) return
|
|
520
|
+
await this.checkAndAddOtherNamespaceAddresses(
|
|
521
|
+
connectedNamespace,
|
|
522
|
+
provider,
|
|
523
|
+
availableAddresses,
|
|
524
|
+
silentOnly
|
|
525
|
+
)
|
|
526
|
+
}
|
|
497
527
|
|
|
498
528
|
if (targetNamespace === 'eip155') {
|
|
499
529
|
// Check Ethereum connection
|
|
@@ -534,11 +564,7 @@ export class ConnectionManager {
|
|
|
534
564
|
availableAddresses.push(...ethAddresses)
|
|
535
565
|
}
|
|
536
566
|
|
|
537
|
-
await
|
|
538
|
-
'eip155',
|
|
539
|
-
provider,
|
|
540
|
-
availableAddresses
|
|
541
|
-
)
|
|
567
|
+
await gatherOthers('eip155')
|
|
542
568
|
} else if (targetNamespace === 'solana') {
|
|
543
569
|
// Check Solana connection
|
|
544
570
|
const solanaAccount = this.solanaService.getAccount()
|
|
@@ -551,10 +577,16 @@ export class ConnectionManager {
|
|
|
551
577
|
if (walletUuid) {
|
|
552
578
|
const wallet = this.solanaService.findWalletByUuid(walletUuid)
|
|
553
579
|
if (wallet?.adapter) {
|
|
554
|
-
const address =
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
580
|
+
const address = silentOnly
|
|
581
|
+
? await this.solanaService.checkExistingConnectionSilently(
|
|
582
|
+
wallet.adapter,
|
|
583
|
+
walletUuid,
|
|
584
|
+
supportsStandardConnect(wallet)
|
|
585
|
+
)
|
|
586
|
+
: await this.solanaService.checkExistingConnection(
|
|
587
|
+
wallet.adapter,
|
|
588
|
+
walletUuid
|
|
589
|
+
)
|
|
558
590
|
if (address) {
|
|
559
591
|
currentAddress = address
|
|
560
592
|
this.solanaService.setConnectionState(
|
|
@@ -576,11 +608,7 @@ export class ConnectionManager {
|
|
|
576
608
|
availableAddresses.push(...solanaAddresses)
|
|
577
609
|
}
|
|
578
610
|
|
|
579
|
-
await
|
|
580
|
-
'solana',
|
|
581
|
-
provider,
|
|
582
|
-
availableAddresses
|
|
583
|
-
)
|
|
611
|
+
await gatherOthers('solana')
|
|
584
612
|
} else if (targetNamespace === 'tron') {
|
|
585
613
|
// Check Tron connection
|
|
586
614
|
const tronAccount = this.tronService.getAccount()
|
|
@@ -613,11 +641,7 @@ export class ConnectionManager {
|
|
|
613
641
|
availableAddresses.push(...tronAddresses)
|
|
614
642
|
}
|
|
615
643
|
|
|
616
|
-
await
|
|
617
|
-
'tron',
|
|
618
|
-
provider,
|
|
619
|
-
availableAddresses
|
|
620
|
-
)
|
|
644
|
+
await gatherOthers('tron')
|
|
621
645
|
} else if (targetNamespace === 'tvm') {
|
|
622
646
|
const tonAccount = this.tonService.getAccount()
|
|
623
647
|
if (tonAccount) {
|
|
@@ -638,11 +662,7 @@ export class ConnectionManager {
|
|
|
638
662
|
availableAddresses.push(...tonAddresses)
|
|
639
663
|
}
|
|
640
664
|
|
|
641
|
-
await
|
|
642
|
-
'tvm',
|
|
643
|
-
provider,
|
|
644
|
-
availableAddresses
|
|
645
|
-
)
|
|
665
|
+
await gatherOthers('tvm')
|
|
646
666
|
} else if (targetNamespace === 'bip122') {
|
|
647
667
|
// A live session only counts as "already connected" when it satisfies the
|
|
648
668
|
// caller's pinned allow-list. Otherwise fall through so the prompting
|
|
@@ -692,11 +712,7 @@ export class ConnectionManager {
|
|
|
692
712
|
availableAddresses.push(...bitcoinAddresses)
|
|
693
713
|
}
|
|
694
714
|
|
|
695
|
-
await
|
|
696
|
-
'bip122',
|
|
697
|
-
provider,
|
|
698
|
-
availableAddresses
|
|
699
|
-
)
|
|
715
|
+
await gatherOthers('bip122')
|
|
700
716
|
}
|
|
701
717
|
|
|
702
718
|
return { address: currentAddress, availableAddresses }
|
|
@@ -707,7 +723,8 @@ export class ConnectionManager {
|
|
|
707
723
|
*/
|
|
708
724
|
private async checkAndAddEthereumAddresses(
|
|
709
725
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
710
|
-
availableAddresses: AvailableAddress[]
|
|
726
|
+
availableAddresses: AvailableAddress[],
|
|
727
|
+
silentOnly = false
|
|
711
728
|
): Promise<SecondaryGatherOutcome> {
|
|
712
729
|
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
713
730
|
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
@@ -730,7 +747,7 @@ export class ConnectionManager {
|
|
|
730
747
|
const ethAddress =
|
|
731
748
|
accounts && accounts.length > 0
|
|
732
749
|
? accounts[0]
|
|
733
|
-
: skipFramedSecondaryConnect()
|
|
750
|
+
: silentOnly || skipFramedSecondaryConnect()
|
|
734
751
|
? undefined
|
|
735
752
|
: await this.ethereumService.connect(
|
|
736
753
|
ethWallet.provider,
|
|
@@ -770,7 +787,8 @@ export class ConnectionManager {
|
|
|
770
787
|
*/
|
|
771
788
|
private async checkAndAddSolanaAddresses(
|
|
772
789
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
773
|
-
availableAddresses: AvailableAddress[]
|
|
790
|
+
availableAddresses: AvailableAddress[],
|
|
791
|
+
silentOnly = false
|
|
774
792
|
): Promise<SecondaryGatherOutcome> {
|
|
775
793
|
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
776
794
|
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
@@ -793,13 +811,19 @@ export class ConnectionManager {
|
|
|
793
811
|
this.solanaService.findWalletByUuid(solanaWalletUuid)
|
|
794
812
|
if (solanaWallet?.adapter) {
|
|
795
813
|
try {
|
|
796
|
-
const existingAddress =
|
|
797
|
-
await this.solanaService.
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
814
|
+
const existingAddress = silentOnly
|
|
815
|
+
? await this.solanaService.checkExistingConnectionSilently(
|
|
816
|
+
solanaWallet.adapter,
|
|
817
|
+
solanaWalletUuid,
|
|
818
|
+
supportsStandardConnect(solanaWallet)
|
|
819
|
+
)
|
|
820
|
+
: await this.solanaService.checkExistingConnection(
|
|
821
|
+
solanaWallet.adapter,
|
|
822
|
+
solanaWalletUuid,
|
|
823
|
+
{ allowSilentReconnect: !skipLegacyConnect }
|
|
824
|
+
)
|
|
802
825
|
const canConnect =
|
|
826
|
+
!silentOnly &&
|
|
803
827
|
!skipLegacyConnect &&
|
|
804
828
|
!skipFramedSecondaryConnect(/* namespaceSafeFramed */ true)
|
|
805
829
|
const solanaAddress =
|
|
@@ -866,7 +890,8 @@ export class ConnectionManager {
|
|
|
866
890
|
*/
|
|
867
891
|
private async checkAndAddTronAddresses(
|
|
868
892
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
869
|
-
availableAddresses: AvailableAddress[]
|
|
893
|
+
availableAddresses: AvailableAddress[],
|
|
894
|
+
silentOnly = false
|
|
870
895
|
): Promise<SecondaryGatherOutcome> {
|
|
871
896
|
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
872
897
|
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
@@ -885,7 +910,8 @@ export class ConnectionManager {
|
|
|
885
910
|
(await this.tronService.checkExistingConnection(
|
|
886
911
|
tronWallet.provider
|
|
887
912
|
)) ||
|
|
888
|
-
(
|
|
913
|
+
(silentOnly ||
|
|
914
|
+
skipFramedSecondaryConnect(/* namespaceSafeFramed */ true)
|
|
889
915
|
? undefined
|
|
890
916
|
: await this.tronService.connect(tronWallet.provider))
|
|
891
917
|
if (address) {
|
|
@@ -919,7 +945,8 @@ export class ConnectionManager {
|
|
|
919
945
|
*/
|
|
920
946
|
private async checkAndAddTonAddresses(
|
|
921
947
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
922
|
-
availableAddresses: AvailableAddress[]
|
|
948
|
+
availableAddresses: AvailableAddress[],
|
|
949
|
+
silentOnly = false
|
|
923
950
|
): Promise<SecondaryGatherOutcome> {
|
|
924
951
|
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
925
952
|
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
@@ -933,7 +960,7 @@ export class ConnectionManager {
|
|
|
933
960
|
if (!tonAccount) {
|
|
934
961
|
const jsBridgeKey =
|
|
935
962
|
provider.namespaceMetaData?.tvm?.detectedWallet?.jsBridgeKey
|
|
936
|
-
if (jsBridgeKey && !skipFramedSecondaryConnect()) {
|
|
963
|
+
if (jsBridgeKey && !silentOnly && !skipFramedSecondaryConnect()) {
|
|
937
964
|
try {
|
|
938
965
|
const result = await this.tonService.connect(jsBridgeKey)
|
|
939
966
|
tonAccount = result.address
|
|
@@ -1010,26 +1037,35 @@ export class ConnectionManager {
|
|
|
1010
1037
|
private async checkAndAddOtherNamespaceAddresses(
|
|
1011
1038
|
connectedNamespace: 'eip155' | 'solana' | 'tron' | 'tvm' | 'bip122',
|
|
1012
1039
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
1013
|
-
availableAddresses: AvailableAddress[]
|
|
1040
|
+
availableAddresses: AvailableAddress[],
|
|
1041
|
+
silentOnly = false
|
|
1014
1042
|
): Promise<void> {
|
|
1015
1043
|
if (connectedNamespace !== 'eip155') {
|
|
1016
1044
|
await this.gatherNamespace('eip155', () =>
|
|
1017
|
-
this.checkAndAddEthereumAddresses(
|
|
1045
|
+
this.checkAndAddEthereumAddresses(
|
|
1046
|
+
provider,
|
|
1047
|
+
availableAddresses,
|
|
1048
|
+
silentOnly
|
|
1049
|
+
)
|
|
1018
1050
|
)
|
|
1019
1051
|
}
|
|
1020
1052
|
if (connectedNamespace !== 'solana') {
|
|
1021
1053
|
await this.gatherNamespace('solana', () =>
|
|
1022
|
-
this.checkAndAddSolanaAddresses(
|
|
1054
|
+
this.checkAndAddSolanaAddresses(
|
|
1055
|
+
provider,
|
|
1056
|
+
availableAddresses,
|
|
1057
|
+
silentOnly
|
|
1058
|
+
)
|
|
1023
1059
|
)
|
|
1024
1060
|
}
|
|
1025
1061
|
if (connectedNamespace !== 'tron') {
|
|
1026
1062
|
await this.gatherNamespace('tron', () =>
|
|
1027
|
-
this.checkAndAddTronAddresses(provider, availableAddresses)
|
|
1063
|
+
this.checkAndAddTronAddresses(provider, availableAddresses, silentOnly)
|
|
1028
1064
|
)
|
|
1029
1065
|
}
|
|
1030
1066
|
if (connectedNamespace !== 'tvm') {
|
|
1031
1067
|
await this.gatherNamespace('tvm', () =>
|
|
1032
|
-
this.checkAndAddTonAddresses(provider, availableAddresses)
|
|
1068
|
+
this.checkAndAddTonAddresses(provider, availableAddresses, silentOnly)
|
|
1033
1069
|
)
|
|
1034
1070
|
}
|
|
1035
1071
|
if (connectedNamespace !== 'bip122') {
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { SolanaWalletService } from './solana-wallet-service'
|
|
3
|
+
import { StorageService } from '../storage-service'
|
|
4
|
+
import type { SolanaAdapter } from '../../wallet-standard-discovery'
|
|
5
|
+
|
|
6
|
+
// ONC-1975: the silent-only probe must return an already-authorized address or
|
|
7
|
+
// null, and must NEVER reach the interactive `adapter.connect()` or make a wallet
|
|
8
|
+
// request. A Wallet Standard wallet that already exposes an account to this
|
|
9
|
+
// origin is adopted through `autoConnect()`, which then connects to that account
|
|
10
|
+
// without calling the wallet's `standard:connect`. Without an exposed account
|
|
11
|
+
// nothing is called: some wallets ignore `silent: true` and show a popup, and a
|
|
12
|
+
// `standard:connect` that never settles would wedge the adapter. The legacy
|
|
13
|
+
// injected fallback never gets `autoConnect()`, a plain prompting connect there.
|
|
14
|
+
describe('SolanaWalletService.checkExistingConnectionSilently', () => {
|
|
15
|
+
function setup({
|
|
16
|
+
exposedAccounts,
|
|
17
|
+
withWallet = true
|
|
18
|
+
}: {
|
|
19
|
+
exposedAccounts: number
|
|
20
|
+
withWallet?: boolean
|
|
21
|
+
}) {
|
|
22
|
+
const storage = new StorageService()
|
|
23
|
+
// Even a "previously connected" flag must not trigger the storage-flag
|
|
24
|
+
// reconnect, which calls the interactive `adapter.connect()`.
|
|
25
|
+
vi.spyOn(storage, 'wasSolanaWalletPreviouslyConnected').mockReturnValue(
|
|
26
|
+
true
|
|
27
|
+
)
|
|
28
|
+
const service = new SolanaWalletService(storage)
|
|
29
|
+
const connect = vi.fn().mockImplementation(async () => {
|
|
30
|
+
adapter.publicKey = { toBase58: () => 'SolPrompted' }
|
|
31
|
+
})
|
|
32
|
+
// Mirrors StandardWalletAdapter: with an exposed account it adopts it
|
|
33
|
+
// directly; without one it would call the wallet's `standard:connect`.
|
|
34
|
+
const standardConnect = vi.fn()
|
|
35
|
+
const autoConnect = vi.fn().mockImplementation(async () => {
|
|
36
|
+
if (!adapter.wallet?.accounts.length) {
|
|
37
|
+
await standardConnect({ silent: true })
|
|
38
|
+
throw new Error('not authorized')
|
|
39
|
+
}
|
|
40
|
+
adapter.publicKey = { toBase58: () => 'SolSilent' }
|
|
41
|
+
})
|
|
42
|
+
const adapter = {
|
|
43
|
+
publicKey: undefined as { toBase58(): string } | undefined,
|
|
44
|
+
connecting: false,
|
|
45
|
+
connect,
|
|
46
|
+
autoConnect,
|
|
47
|
+
wallet: withWallet
|
|
48
|
+
? {
|
|
49
|
+
accounts: Array.from({ length: exposedAccounts }, (_, i) => ({
|
|
50
|
+
address: `Sol${i}`
|
|
51
|
+
}))
|
|
52
|
+
}
|
|
53
|
+
: undefined
|
|
54
|
+
}
|
|
55
|
+
return { service, adapter, connect, autoConnect, standardConnect }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
it('returns an already-present publicKey without any connect', async () => {
|
|
59
|
+
const { service, adapter, connect, autoConnect } = setup({
|
|
60
|
+
exposedAccounts: 1
|
|
61
|
+
})
|
|
62
|
+
adapter.publicKey = { toBase58: () => 'SolLive' }
|
|
63
|
+
|
|
64
|
+
const address = await service.checkExistingConnectionSilently(
|
|
65
|
+
adapter as unknown as SolanaAdapter,
|
|
66
|
+
'wallet-1',
|
|
67
|
+
true
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
expect(address).toBe('SolLive')
|
|
71
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
72
|
+
expect(connect).not.toHaveBeenCalled()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('adopts an account the wallet already exposes, with no wallet request', async () => {
|
|
76
|
+
const { service, adapter, connect, autoConnect, standardConnect } = setup({
|
|
77
|
+
exposedAccounts: 1
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const address = await service.checkExistingConnectionSilently(
|
|
81
|
+
adapter as unknown as SolanaAdapter,
|
|
82
|
+
'wallet-1',
|
|
83
|
+
true
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
expect(address).toBe('SolSilent')
|
|
87
|
+
expect(autoConnect).toHaveBeenCalledTimes(1)
|
|
88
|
+
expect(standardConnect).not.toHaveBeenCalled()
|
|
89
|
+
expect(connect).not.toHaveBeenCalled()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('returns null without touching the wallet when it exposes no account', async () => {
|
|
93
|
+
const { service, adapter, connect, autoConnect, standardConnect } = setup({
|
|
94
|
+
exposedAccounts: 0
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const address = await service.checkExistingConnectionSilently(
|
|
98
|
+
adapter as unknown as SolanaAdapter,
|
|
99
|
+
'wallet-1',
|
|
100
|
+
true
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
expect(address).toBeNull()
|
|
104
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
105
|
+
expect(standardConnect).not.toHaveBeenCalled()
|
|
106
|
+
expect(connect).not.toHaveBeenCalled()
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('returns null for an adapter that carries no wallet (bridged)', async () => {
|
|
110
|
+
const { service, adapter, connect, autoConnect } = setup({
|
|
111
|
+
exposedAccounts: 0,
|
|
112
|
+
withWallet: false
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const address = await service.checkExistingConnectionSilently(
|
|
116
|
+
adapter as unknown as SolanaAdapter,
|
|
117
|
+
'wallet-1',
|
|
118
|
+
true
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
expect(address).toBeNull()
|
|
122
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
123
|
+
expect(connect).not.toHaveBeenCalled()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('does not trust a proxy-shaped wallet.accounts (iframe bridge)', async () => {
|
|
127
|
+
const { service, adapter, connect, autoConnect, standardConnect } = setup({
|
|
128
|
+
exposedAccounts: 0
|
|
129
|
+
})
|
|
130
|
+
// Comlink proxies are function-backed Proxies: every property read, such
|
|
131
|
+
// as `.length`, yields another truthy proxy whatever the parent holds.
|
|
132
|
+
const proxy = (): unknown => new Proxy(() => {}, { get: () => proxy() })
|
|
133
|
+
;(adapter as { wallet: unknown }).wallet = proxy()
|
|
134
|
+
|
|
135
|
+
const address = await service.checkExistingConnectionSilently(
|
|
136
|
+
adapter as unknown as SolanaAdapter,
|
|
137
|
+
'wallet-1',
|
|
138
|
+
true
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
expect(address).toBeNull()
|
|
142
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
143
|
+
expect(standardConnect).not.toHaveBeenCalled()
|
|
144
|
+
expect(connect).not.toHaveBeenCalled()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('never calls autoConnect for a wallet without standard:connect (legacy fallback)', async () => {
|
|
148
|
+
const { service, adapter, connect, autoConnect } = setup({
|
|
149
|
+
exposedAccounts: 1
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const address = await service.checkExistingConnectionSilently(
|
|
153
|
+
adapter as unknown as SolanaAdapter,
|
|
154
|
+
'wallet-1',
|
|
155
|
+
false
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
expect(address).toBeNull()
|
|
159
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
160
|
+
expect(connect).not.toHaveBeenCalled()
|
|
161
|
+
})
|
|
162
|
+
})
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type WalletStandardInfo,
|
|
11
11
|
type LegacyInjectedSolanaDiscoveryFailure
|
|
12
12
|
} from '../../wallet-standard-discovery'
|
|
13
|
+
import type { StandardWalletAdapter } from '@solana/wallet-standard-wallet-adapter-base'
|
|
13
14
|
import { StorageService } from '../storage-service'
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -103,6 +104,53 @@ export class SolanaWalletService {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The silent-only probe (see `ConnectorConnectOptions.silentOnly`): returns
|
|
109
|
+
* the already-authorized address, or null — and NEVER prompts.
|
|
110
|
+
*
|
|
111
|
+
* Passive check first (no storage-flag reconnect: that path calls the
|
|
112
|
+
* interactive `adapter.connect()`). Then, only for a Wallet Standard wallet
|
|
113
|
+
* that ALREADY exposes an account to this origin (`wallet.accounts`),
|
|
114
|
+
* `adapter.autoConnect()` to adopt it. With an account present the Standard
|
|
115
|
+
* adapter connects to it directly and never calls the wallet's
|
|
116
|
+
* `standard:connect`, so no wallet request is made at all. That gate matters:
|
|
117
|
+
* `silent: true` is only a hint the spec lets wallets ignore (Trust and
|
|
118
|
+
* MetaMask show a normal Connect popup for it), and a `standard:connect` that
|
|
119
|
+
* never settles would leave the adapter `connecting` until reload, turning the
|
|
120
|
+
* user's later tap into a no-op. The price is a miss for a wallet that trusts
|
|
121
|
+
* the origin but has not re-exposed its accounts on this page; the caller
|
|
122
|
+
* falls back to its normal connect. Never called for the legacy injected
|
|
123
|
+
* fallback, whose inherited `autoConnect()` is a plain prompting `connect()`.
|
|
124
|
+
*/
|
|
125
|
+
async checkExistingConnectionSilently(
|
|
126
|
+
adapter: SolanaAdapter,
|
|
127
|
+
walletUuid: string,
|
|
128
|
+
supportsStandardConnect: boolean
|
|
129
|
+
): Promise<string | null> {
|
|
130
|
+
const passive = await this.checkExistingConnection(adapter, walletUuid, {
|
|
131
|
+
allowSilentReconnect: false
|
|
132
|
+
})
|
|
133
|
+
if (passive || !supportsStandardConnect) {
|
|
134
|
+
return passive
|
|
135
|
+
}
|
|
136
|
+
// A bridged (framed) adapter is a Comlink proxy: `wallet`, `accounts` and
|
|
137
|
+
// `length` are all truthy proxies whatever the parent holds. Only a
|
|
138
|
+
// materialized, nonempty array proves an account, so a bridged adapter
|
|
139
|
+
// never gets the `autoConnect()` probe.
|
|
140
|
+
const exposedAccounts = (adapter as Partial<StandardWalletAdapter>).wallet
|
|
141
|
+
?.accounts
|
|
142
|
+
if (!Array.isArray(exposedAccounts) || exposedAccounts.length === 0) {
|
|
143
|
+
return null
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
await (adapter as StandardWalletAdapter).autoConnect()
|
|
147
|
+
return (await adapter.publicKey?.toBase58()) ?? null
|
|
148
|
+
} catch {
|
|
149
|
+
// The account vanished between the gate and the adopt: no address.
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
106
154
|
/**
|
|
107
155
|
* Connect to wallet
|
|
108
156
|
*/
|