@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.
@@ -1794,3 +1794,449 @@ describe('ConnectionManager — secondary gather outcome fidelity (ONC-183 revie
1794
1794
  expect(gatherStep('solana')).toMatchObject({ outcome: 'ok' })
1795
1795
  })
1796
1796
  })
1797
+
1798
+ // ONC-1975: a silent-only check must never reach a prompting call — not for the
1799
+ // target namespace, and not through the secondary gathers, which normally fall
1800
+ // back to a PROMPTING connect when their own silent probe comes back empty.
1801
+ describe('ConnectionManager.checkExistingConnections — silentOnly', () => {
1802
+ let ethService: ReturnType<typeof makeEthService>
1803
+ let solanaService: ReturnType<typeof makeSolanaService> & {
1804
+ checkExistingConnectionSilently: ReturnType<typeof vi.fn>
1805
+ }
1806
+ let tronService: ReturnType<typeof makeTronService>
1807
+ let tonService: ReturnType<typeof makeTonService>
1808
+ let bitcoinService: ReturnType<typeof makeBitcoinService>
1809
+ let manager: ConnectionManager
1810
+
1811
+ beforeEach(() => {
1812
+ ethService = makeEthService()
1813
+ solanaService = {
1814
+ ...makeSolanaService(),
1815
+ checkExistingConnectionSilently: vi.fn().mockResolvedValue(null)
1816
+ }
1817
+ tronService = makeTronService()
1818
+ tonService = makeTonService()
1819
+ bitcoinService = makeBitcoinService()
1820
+ manager = new ConnectionManager(
1821
+ ethService as any,
1822
+ solanaService as any,
1823
+ tronService as any,
1824
+ tonService as any,
1825
+ bitcoinService as any
1826
+ )
1827
+ })
1828
+
1829
+ const multiChainProvider = () =>
1830
+ makeProvider({
1831
+ eip155: { detectedWallet: { uuid: 'mm-eip155' } },
1832
+ solana: { detectedWallet: { uuid: 'mm-solana' } },
1833
+ tron: { detectedWallet: { uuid: 'mm-tron' } },
1834
+ tvm: { detectedWallet: { jsBridgeKey: 'mmton' } }
1835
+ })
1836
+
1837
+ function expectNoPromptingCall() {
1838
+ expect(ethService.connect).not.toHaveBeenCalled()
1839
+ expect(solanaService.connect).not.toHaveBeenCalled()
1840
+ expect(tronService.connect).not.toHaveBeenCalled()
1841
+ expect(tonService.connect).not.toHaveBeenCalled()
1842
+ expect(bitcoinService.connect).not.toHaveBeenCalled()
1843
+ // The default Solana check can reconnect through the interactive
1844
+ // `adapter.connect()`; silent-only must use the silent variant instead.
1845
+ expect(solanaService.checkExistingConnection).not.toHaveBeenCalled()
1846
+ }
1847
+
1848
+ it('reports no address and skips every secondary gather when the target is not authorized', async () => {
1849
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
1850
+ ethService.checkExistingConnection.mockResolvedValue([])
1851
+ solanaService.findWalletByUuid.mockReturnValue({
1852
+ adapter: {},
1853
+ features: ['standard:connect']
1854
+ })
1855
+
1856
+ const result = await manager.checkExistingConnections(
1857
+ 'eip155',
1858
+ multiChainProvider(),
1859
+ undefined,
1860
+ { silentOnly: true }
1861
+ )
1862
+
1863
+ expect(result.address).toBeNull()
1864
+ expect(result.availableAddresses).toEqual([])
1865
+ // The target was not authorized, so the gathers never ran at all.
1866
+ expect(solanaService.checkExistingConnectionSilently).not.toHaveBeenCalled()
1867
+ expect(tronService.checkExistingConnection).not.toHaveBeenCalled()
1868
+ expectNoPromptingCall()
1869
+ })
1870
+
1871
+ it('connects an authorized target and gathers secondaries without their prompting fallbacks', async () => {
1872
+ const solanaAdapter = {}
1873
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
1874
+ ethService.checkExistingConnection.mockResolvedValue(['0xABC'])
1875
+ solanaService.findWalletByUuid.mockReturnValue({
1876
+ adapter: solanaAdapter,
1877
+ features: ['standard:connect']
1878
+ })
1879
+ tronService.findWalletByUuid.mockReturnValue({ provider: {} })
1880
+
1881
+ const result = await manager.checkExistingConnections(
1882
+ 'eip155',
1883
+ multiChainProvider(),
1884
+ undefined,
1885
+ { silentOnly: true }
1886
+ )
1887
+
1888
+ expect(result.address).toBe('0xABC')
1889
+ expect(result.availableAddresses).toEqual([
1890
+ { address: '0xABC', networkId: 'eip155:1' }
1891
+ ])
1892
+ // Secondaries were probed silently, and their misses did NOT fall back to
1893
+ // a prompting connect.
1894
+ expect(solanaService.checkExistingConnectionSilently).toHaveBeenCalledWith(
1895
+ solanaAdapter,
1896
+ 'mm-solana',
1897
+ true
1898
+ )
1899
+ expect(tronService.checkExistingConnection).toHaveBeenCalled()
1900
+ expect(tonService.checkExistingConnection).toHaveBeenCalled()
1901
+ expectNoPromptingCall()
1902
+ })
1903
+
1904
+ it('keeps a silently-authorized secondary address', async () => {
1905
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
1906
+ ethService.checkExistingConnection.mockResolvedValue(['0xABC'])
1907
+ solanaService.findWalletByUuid.mockReturnValue({
1908
+ adapter: {},
1909
+ features: ['standard:connect']
1910
+ })
1911
+ solanaService.checkExistingConnectionSilently.mockResolvedValue('SolAddr9')
1912
+
1913
+ const result = await manager.checkExistingConnections(
1914
+ 'eip155',
1915
+ makeProvider({
1916
+ eip155: { detectedWallet: { uuid: 'mm-eip155' } },
1917
+ solana: { detectedWallet: { uuid: 'mm-solana' } }
1918
+ }),
1919
+ undefined,
1920
+ { silentOnly: true }
1921
+ )
1922
+
1923
+ expect(result.availableAddresses).toEqual([
1924
+ { address: '0xABC', networkId: 'eip155:1' },
1925
+ {
1926
+ address: 'SolAddr9',
1927
+ networkId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
1928
+ }
1929
+ ])
1930
+ expectNoPromptingCall()
1931
+ })
1932
+
1933
+ it('does not prompt the EVM secondary of an authorized non-EVM target', async () => {
1934
+ solanaService.findWalletByUuid.mockReturnValue({
1935
+ adapter: {},
1936
+ features: ['standard:connect']
1937
+ })
1938
+ solanaService.checkExistingConnectionSilently.mockResolvedValue('SolAddr9')
1939
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
1940
+ ethService.checkExistingConnection.mockResolvedValue([])
1941
+
1942
+ const result = await manager.checkExistingConnections(
1943
+ 'solana',
1944
+ multiChainProvider(),
1945
+ undefined,
1946
+ { silentOnly: true }
1947
+ )
1948
+
1949
+ expect(result.address).toBe('SolAddr9')
1950
+ expect(ethService.checkExistingConnection).toHaveBeenCalled()
1951
+ expectNoPromptingCall()
1952
+ })
1953
+
1954
+ it('probes a Solana target silently, telling the probe whether autoConnect is safe', async () => {
1955
+ const legacyAdapter = {}
1956
+ // A legacy injected wallet advertises no `standard:connect`.
1957
+ solanaService.findWalletByUuid.mockReturnValue({
1958
+ adapter: legacyAdapter,
1959
+ features: ['solana:signTransaction']
1960
+ })
1961
+
1962
+ const result = await manager.checkExistingConnections(
1963
+ 'solana',
1964
+ makeProvider({ solana: { detectedWallet: { uuid: 'legacy-solana' } } }),
1965
+ undefined,
1966
+ { silentOnly: true }
1967
+ )
1968
+
1969
+ expect(result.address).toBeNull()
1970
+ expect(solanaService.checkExistingConnectionSilently).toHaveBeenCalledWith(
1971
+ legacyAdapter,
1972
+ 'legacy-solana',
1973
+ false
1974
+ )
1975
+ expectNoPromptingCall()
1976
+ })
1977
+ })
1978
+
1979
+ // ONC-1975: silent-only per target namespace (Tron, TON, Bitcoin), and while
1980
+ // framed, where the secondary gathers have extra eager connects of their own.
1981
+ describe('ConnectionManager.checkExistingConnections — silentOnly, other targets and framed', () => {
1982
+ let ethService: ReturnType<typeof makeEthService>
1983
+ let solanaService: ReturnType<typeof makeSolanaService> & {
1984
+ checkExistingConnectionSilently: ReturnType<typeof vi.fn>
1985
+ }
1986
+ let tronService: ReturnType<typeof makeTronService>
1987
+ let tonService: ReturnType<typeof makeTonService>
1988
+ let bitcoinService: ReturnType<typeof makeBitcoinService>
1989
+ let manager: ConnectionManager
1990
+
1991
+ beforeEach(() => {
1992
+ ethService = makeEthService()
1993
+ solanaService = {
1994
+ ...makeSolanaService(),
1995
+ checkExistingConnectionSilently: vi.fn().mockResolvedValue(null)
1996
+ }
1997
+ tronService = makeTronService()
1998
+ tonService = makeTonService()
1999
+ bitcoinService = makeBitcoinService()
2000
+ manager = new ConnectionManager(
2001
+ ethService as any,
2002
+ solanaService as any,
2003
+ tronService as any,
2004
+ tonService as any,
2005
+ bitcoinService as any
2006
+ )
2007
+ })
2008
+
2009
+ afterEach(() => {
2010
+ Object.defineProperty(window, 'top', { value: window, configurable: true })
2011
+ })
2012
+
2013
+ const silent = { silentOnly: true }
2014
+
2015
+ function expectNoPromptingCall() {
2016
+ expect(ethService.connect).not.toHaveBeenCalled()
2017
+ expect(solanaService.connect).not.toHaveBeenCalled()
2018
+ expect(tronService.connect).not.toHaveBeenCalled()
2019
+ expect(tonService.connect).not.toHaveBeenCalled()
2020
+ expect(bitcoinService.connect).not.toHaveBeenCalled()
2021
+ }
2022
+
2023
+ describe('Tron target', () => {
2024
+ const provider = () =>
2025
+ makeProvider({
2026
+ tron: { detectedWallet: { uuid: 'tl-tron' } },
2027
+ eip155: { detectedWallet: { uuid: 'tl-eip155' } }
2028
+ })
2029
+
2030
+ it('restores an already-authorized wallet without prompting', async () => {
2031
+ tronService.findWalletByUuid.mockReturnValue({ provider: {} })
2032
+ tronService.checkExistingConnection.mockResolvedValue('TTronAddr')
2033
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2034
+ ethService.checkExistingConnection.mockResolvedValue([])
2035
+
2036
+ const result = await manager.checkExistingConnections(
2037
+ 'tron',
2038
+ provider(),
2039
+ undefined,
2040
+ silent
2041
+ )
2042
+
2043
+ expect(result.address).toBe('TTronAddr')
2044
+ expect(tronService.setConnectionState).toHaveBeenCalled()
2045
+ expectNoPromptingCall()
2046
+ })
2047
+
2048
+ it('reports no address and gathers nothing when the wallet is not authorized', async () => {
2049
+ tronService.findWalletByUuid.mockReturnValue({ provider: {} })
2050
+ tronService.checkExistingConnection.mockResolvedValue(null)
2051
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2052
+
2053
+ const result = await manager.checkExistingConnections(
2054
+ 'tron',
2055
+ provider(),
2056
+ undefined,
2057
+ silent
2058
+ )
2059
+
2060
+ expect(result.address).toBeNull()
2061
+ expect(result.availableAddresses).toEqual([])
2062
+ expect(ethService.checkExistingConnection).not.toHaveBeenCalled()
2063
+ expectNoPromptingCall()
2064
+ })
2065
+ })
2066
+
2067
+ describe('TON target', () => {
2068
+ const provider = () =>
2069
+ makeProvider({
2070
+ tvm: { detectedWallet: { jsBridgeKey: 'tonkeeper' } },
2071
+ eip155: { detectedWallet: { uuid: 'tk-eip155' } }
2072
+ })
2073
+
2074
+ it('restores an already-authorized wallet without prompting', async () => {
2075
+ tonService.checkExistingConnection.mockResolvedValue('UQTonAddr')
2076
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2077
+ ethService.checkExistingConnection.mockResolvedValue([])
2078
+
2079
+ const result = await manager.checkExistingConnections(
2080
+ 'tvm',
2081
+ provider(),
2082
+ undefined,
2083
+ silent
2084
+ )
2085
+
2086
+ expect(result.address).toBe('UQTonAddr')
2087
+ expect(tonService.setConnectionState).toHaveBeenCalledWith('UQTonAddr')
2088
+ expectNoPromptingCall()
2089
+ })
2090
+
2091
+ it('reports no address and gathers nothing when the wallet is not authorized', async () => {
2092
+ tonService.checkExistingConnection.mockResolvedValue(null)
2093
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2094
+
2095
+ const result = await manager.checkExistingConnections(
2096
+ 'tvm',
2097
+ provider(),
2098
+ undefined,
2099
+ silent
2100
+ )
2101
+
2102
+ expect(result.address).toBeNull()
2103
+ expect(result.availableAddresses).toEqual([])
2104
+ expect(ethService.checkExistingConnection).not.toHaveBeenCalled()
2105
+ expectNoPromptingCall()
2106
+ })
2107
+ })
2108
+
2109
+ describe('Bitcoin target', () => {
2110
+ const provider = () =>
2111
+ makeProvider({
2112
+ bip122: { detectedWallet: { uuid: 'xv-bip122' } },
2113
+ eip155: { detectedWallet: { uuid: 'xv-eip155' } }
2114
+ })
2115
+
2116
+ it('restores an already-authorized wallet without prompting', async () => {
2117
+ const wallet = { uuid: 'xv-bip122', wallet: {} }
2118
+ bitcoinService.findWalletByUuid.mockReturnValue(wallet)
2119
+ bitcoinService.checkExistingConnection.mockResolvedValue('bc1qtrusted')
2120
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2121
+ ethService.checkExistingConnection.mockResolvedValue([])
2122
+
2123
+ const result = await manager.checkExistingConnections(
2124
+ 'bip122',
2125
+ provider(),
2126
+ undefined,
2127
+ silent
2128
+ )
2129
+
2130
+ expect(result.address).toBe('bc1qtrusted')
2131
+ expect(bitcoinService.setConnectionState).toHaveBeenCalledWith(
2132
+ wallet,
2133
+ 'bc1qtrusted'
2134
+ )
2135
+ expectNoPromptingCall()
2136
+ })
2137
+
2138
+ it('reports no address and gathers nothing when the wallet is not authorized', async () => {
2139
+ bitcoinService.findWalletByUuid.mockReturnValue({
2140
+ uuid: 'xv-bip122',
2141
+ wallet: {}
2142
+ })
2143
+ bitcoinService.checkExistingConnection.mockResolvedValue(null)
2144
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2145
+
2146
+ const result = await manager.checkExistingConnections(
2147
+ 'bip122',
2148
+ provider(),
2149
+ undefined,
2150
+ silent
2151
+ )
2152
+
2153
+ expect(result.address).toBeNull()
2154
+ expect(result.availableAddresses).toEqual([])
2155
+ expect(ethService.checkExistingConnection).not.toHaveBeenCalled()
2156
+ expectNoPromptingCall()
2157
+ })
2158
+
2159
+ it('gathers an already-authorized Bitcoin secondary of an EVM target, never connecting it', async () => {
2160
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2161
+ ethService.checkExistingConnection.mockResolvedValue(['0xABC'])
2162
+ bitcoinService.findWalletByUuid.mockReturnValue({
2163
+ uuid: 'xv-bip122',
2164
+ wallet: {}
2165
+ })
2166
+ bitcoinService.checkExistingConnection.mockResolvedValue('bc1qsecondary')
2167
+
2168
+ const result = await manager.checkExistingConnections(
2169
+ 'eip155',
2170
+ provider(),
2171
+ undefined,
2172
+ silent
2173
+ )
2174
+
2175
+ expect(result.availableAddresses).toContainEqual({
2176
+ address: 'bc1qsecondary',
2177
+ networkId: 'bip122:000000000019d6689c085ae165831e93'
2178
+ })
2179
+ expectNoPromptingCall()
2180
+ })
2181
+ })
2182
+
2183
+ // Framed (iframe bridge child): the secondary gathers have eager connects
2184
+ // that run in a frame — Solana always, TON unless in the wallet in-app
2185
+ // browser. Silent-only must suppress every one of them.
2186
+ describe('framed (iframe bridge child)', () => {
2187
+ beforeEach(() => {
2188
+ Object.defineProperty(window, 'top', { value: {}, configurable: true })
2189
+ })
2190
+
2191
+ it('does not run the eager secondary Solana/TON/Tron connects after an authorized EVM target', async () => {
2192
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2193
+ ethService.checkExistingConnection.mockResolvedValue(['0xABC'])
2194
+ solanaService.findWalletByUuid.mockReturnValue({
2195
+ adapter: {},
2196
+ features: ['standard:connect']
2197
+ })
2198
+ tronService.findWalletByUuid.mockReturnValue({ provider: {} })
2199
+
2200
+ const result = await manager.checkExistingConnections(
2201
+ 'eip155',
2202
+ makeProvider({
2203
+ eip155: { detectedWallet: { uuid: 'mm-eip155' } },
2204
+ solana: { detectedWallet: { uuid: 'mm-solana' } },
2205
+ tron: { detectedWallet: { uuid: 'mm-tron' } },
2206
+ tvm: { detectedWallet: { jsBridgeKey: 'mmton' } }
2207
+ }),
2208
+ undefined,
2209
+ silent
2210
+ )
2211
+
2212
+ expect(result.address).toBe('0xABC')
2213
+ expect(solanaService.checkExistingConnectionSilently).toHaveBeenCalled()
2214
+ expectNoPromptingCall()
2215
+ })
2216
+
2217
+ it('reports no address and probes no secondary when the target is not authorized', async () => {
2218
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
2219
+ ethService.checkExistingConnection.mockResolvedValue([])
2220
+ solanaService.findWalletByUuid.mockReturnValue({
2221
+ adapter: {},
2222
+ features: ['standard:connect']
2223
+ })
2224
+
2225
+ const result = await manager.checkExistingConnections(
2226
+ 'eip155',
2227
+ makeProvider({
2228
+ eip155: { detectedWallet: { uuid: 'mm-eip155' } },
2229
+ solana: { detectedWallet: { uuid: 'mm-solana' } }
2230
+ }),
2231
+ undefined,
2232
+ silent
2233
+ )
2234
+
2235
+ expect(result.address).toBeNull()
2236
+ expect(
2237
+ solanaService.checkExistingConnectionSilently
2238
+ ).not.toHaveBeenCalled()
2239
+ expectNoPromptingCall()
2240
+ })
2241
+ })
2242
+ })