@meshconnect/uwc-injected-connector 0.16.6 → 0.17.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 +43 -4
- package/dist/injected-connector.d.ts.map +1 -1
- package/dist/injected-connector.js +30 -5
- package/dist/injected-connector.js.map +1 -1
- package/dist/legacy-injected-solana-adapter.d.ts +79 -0
- package/dist/legacy-injected-solana-adapter.d.ts.map +1 -0
- package/dist/legacy-injected-solana-adapter.js +264 -0
- package/dist/legacy-injected-solana-adapter.js.map +1 -0
- package/dist/services/solana/solana-wallet-service.d.ts +3 -3
- package/dist/services/solana/solana-wallet-service.d.ts.map +1 -1
- package/dist/services/solana/solana-wallet-service.js +2 -2
- package/dist/services/solana/solana-wallet-service.js.map +1 -1
- package/dist/wallet-standard-discovery.d.ts +21 -2
- package/dist/wallet-standard-discovery.d.ts.map +1 -1
- package/dist/wallet-standard-discovery.js +63 -7
- package/dist/wallet-standard-discovery.js.map +1 -1
- package/package.json +5 -5
- package/src/injected-connector.test.ts +114 -9
- package/src/injected-connector.ts +81 -12
- package/src/legacy-injected-solana-adapter.test.ts +340 -0
- package/src/legacy-injected-solana-adapter.ts +370 -0
- package/src/services/solana/solana-wallet-service.ts +14 -4
- package/src/wallet-standard-discovery.test.ts +352 -0
- package/src/wallet-standard-discovery.ts +98 -7
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
NetworkId,
|
|
3
3
|
AvailableAddress,
|
|
4
|
-
WalletLifecycleEvent
|
|
4
|
+
WalletLifecycleEvent,
|
|
5
|
+
WalletMetadata
|
|
5
6
|
} from '@meshconnect/uwc-types'
|
|
6
7
|
import {
|
|
7
8
|
getSolanaWallets,
|
|
8
9
|
type SolanaAdapter,
|
|
9
|
-
type WalletStandardInfo
|
|
10
|
+
type WalletStandardInfo,
|
|
11
|
+
type LegacyInjectedSolanaDiscoveryFailure
|
|
10
12
|
} from '../../wallet-standard-discovery'
|
|
11
13
|
import { StorageService } from '../storage-service'
|
|
12
14
|
|
|
@@ -26,8 +28,16 @@ export class SolanaWalletService {
|
|
|
26
28
|
/**
|
|
27
29
|
* Initialize wallet discovery
|
|
28
30
|
*/
|
|
29
|
-
async initializeDiscovery(
|
|
30
|
-
|
|
31
|
+
async initializeDiscovery(
|
|
32
|
+
expectedWallets: WalletMetadata[] = [],
|
|
33
|
+
usingIntegratedBrowser = false,
|
|
34
|
+
onLegacyDiscoveryFailure?: LegacyInjectedSolanaDiscoveryFailure
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
this.detectedWallets = await getSolanaWallets(
|
|
37
|
+
expectedWallets,
|
|
38
|
+
usingIntegratedBrowser,
|
|
39
|
+
onLegacyDiscoveryFailure
|
|
40
|
+
)
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
/**
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import type { WalletMetadata } from '@meshconnect/uwc-types'
|
|
3
|
+
import { solanaNetwork } from '@meshconnect/uwc-constants'
|
|
4
|
+
|
|
5
|
+
// Registry mock — getWallets().get() returns whatever we stage.
|
|
6
|
+
let registryWallets: any[] = []
|
|
7
|
+
vi.mock('@wallet-standard/app', () => ({
|
|
8
|
+
getWallets: () => ({ get: () => registryWallets })
|
|
9
|
+
}))
|
|
10
|
+
|
|
11
|
+
vi.mock('@solana/wallet-adapter-base', () => ({
|
|
12
|
+
isWalletAdapterCompatibleStandardWallet: vi.fn(() => true)
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
vi.mock('@solana/wallet-standard-wallet-adapter-base', () => ({
|
|
16
|
+
StandardWalletAdapter: class {
|
|
17
|
+
wallet: any
|
|
18
|
+
constructor(opts: any) {
|
|
19
|
+
this.wallet = opts.wallet
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
// Isolate discovery from the real adapter. We control the legacy-provider signal
|
|
25
|
+
// per injectedId. vi.hoisted: the factory is hoisted above the file.
|
|
26
|
+
const {
|
|
27
|
+
getInjectedSolanaProvider,
|
|
28
|
+
resolveInjectedProperty,
|
|
29
|
+
MockLegacyAdapter
|
|
30
|
+
} = vi.hoisted(() => ({
|
|
31
|
+
getInjectedSolanaProvider: vi.fn(),
|
|
32
|
+
resolveInjectedProperty: vi.fn(),
|
|
33
|
+
MockLegacyAdapter: class {
|
|
34
|
+
constructor(
|
|
35
|
+
public injectedId: string,
|
|
36
|
+
public name: string
|
|
37
|
+
) {}
|
|
38
|
+
}
|
|
39
|
+
}))
|
|
40
|
+
vi.mock('./legacy-injected-solana-adapter', () => ({
|
|
41
|
+
getInjectedSolanaProvider: (id: string) => getInjectedSolanaProvider(id),
|
|
42
|
+
resolveInjectedProperty: (id: string) => resolveInjectedProperty(id),
|
|
43
|
+
LegacyInjectedSolanaWalletAdapter: MockLegacyAdapter
|
|
44
|
+
}))
|
|
45
|
+
|
|
46
|
+
import { getSolanaWallets } from './wallet-standard-discovery'
|
|
47
|
+
|
|
48
|
+
// Derive from the shared constant (discovery uses `solanaNetwork.id`) so the
|
|
49
|
+
// test can't drift if the canonical Solana CAIP-2 id ever changes.
|
|
50
|
+
const SOLANA_MAINNET = solanaNetwork.id
|
|
51
|
+
|
|
52
|
+
function standardWallet(
|
|
53
|
+
name: string,
|
|
54
|
+
chains: string[] = [SOLANA_MAINNET]
|
|
55
|
+
): any {
|
|
56
|
+
return { name, chains, features: { 'solana:signTransaction': {} } }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Minimal WalletMetadata carrying a solana injectedId + walletStandardName.
|
|
60
|
+
function expectedWallet(
|
|
61
|
+
walletStandardName?: string,
|
|
62
|
+
injectedId?: string
|
|
63
|
+
): WalletMetadata {
|
|
64
|
+
return {
|
|
65
|
+
extensionInjectedProvider: {
|
|
66
|
+
namespaceMetaData: { solana: { walletStandardName, injectedId } }
|
|
67
|
+
}
|
|
68
|
+
} as unknown as WalletMetadata
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe('getSolanaWallets — metadata-driven legacy injected fallback (MFS-805)', () => {
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
registryWallets = []
|
|
74
|
+
getInjectedSolanaProvider.mockReset()
|
|
75
|
+
resolveInjectedProperty.mockReset()
|
|
76
|
+
// default: the legacy global resolves to a provider
|
|
77
|
+
getInjectedSolanaProvider.mockReturnValue({ connect: vi.fn() })
|
|
78
|
+
// default: no raw global present unless a test stages one
|
|
79
|
+
resolveInjectedProperty.mockReturnValue(undefined)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
delete (window as any).UWCBridgeChildInitialized
|
|
84
|
+
delete (window as any).walletStandardWallets
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('adds a legacy entry from solana.injectedId + walletStandardName (Legacy mode)', async () => {
|
|
88
|
+
const wallets = await getSolanaWallets([
|
|
89
|
+
expectedWallet('Base Wallet', 'coinbaseSolana')
|
|
90
|
+
])
|
|
91
|
+
|
|
92
|
+
expect(wallets).toHaveLength(1)
|
|
93
|
+
const w = wallets[0]!
|
|
94
|
+
expect(w.name).toBe('Base Wallet')
|
|
95
|
+
expect(w.chains).toEqual([SOLANA_MAINNET])
|
|
96
|
+
expect(w.uuid).toBe(`base-wallet-${SOLANA_MAINNET.toLowerCase()}`)
|
|
97
|
+
expect(w.adapter).toBeInstanceOf(MockLegacyAdapter)
|
|
98
|
+
// wallet-agnostic: adapter constructed from the metadata injectedId + name
|
|
99
|
+
expect((w.adapter as any).injectedId).toBe('coinbaseSolana')
|
|
100
|
+
expect((w.adapter as any).name).toBe('Base Wallet')
|
|
101
|
+
expect(getInjectedSolanaProvider).toHaveBeenCalledWith('coinbaseSolana')
|
|
102
|
+
// Telemetry signal (MFS-805): legacy-fallback entries are tagged so detection
|
|
103
|
+
// can report the legacy path was exercised.
|
|
104
|
+
expect(w.legacyInjected).toBe(true)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('adds nothing when no expected wallet declares a solana injectedId', async () => {
|
|
108
|
+
const wallets = await getSolanaWallets([expectedWallet('Base Wallet')])
|
|
109
|
+
expect(wallets).toHaveLength(0)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('adds nothing when walletStandardName is missing (needed for core matching)', async () => {
|
|
113
|
+
const wallets = await getSolanaWallets([
|
|
114
|
+
expectedWallet(undefined, 'coinbaseSolana')
|
|
115
|
+
])
|
|
116
|
+
expect(wallets).toHaveLength(0)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('adds nothing when the injectedId global does not resolve to a provider', async () => {
|
|
120
|
+
getInjectedSolanaProvider.mockReturnValue(undefined)
|
|
121
|
+
const wallets = await getSolanaWallets([
|
|
122
|
+
expectedWallet('Base Wallet', 'coinbaseSolana')
|
|
123
|
+
])
|
|
124
|
+
expect(wallets).toHaveLength(0)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('does NOT duplicate when a registry wallet already claims the name', async () => {
|
|
128
|
+
registryWallets = [standardWallet('Base Wallet')]
|
|
129
|
+
const wallets = await getSolanaWallets([
|
|
130
|
+
expectedWallet('Base Wallet', 'coinbaseSolana')
|
|
131
|
+
])
|
|
132
|
+
expect(wallets).toHaveLength(1)
|
|
133
|
+
expect(wallets[0]!.adapter).not.toBeInstanceOf(MockLegacyAdapter)
|
|
134
|
+
// Registry wallets are NOT tagged legacyInjected — the flag must stay unique
|
|
135
|
+
// to the fallback path so the telemetry count can't over-report.
|
|
136
|
+
expect(wallets[0]!.legacyInjected).toBeFalsy()
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('dedupes against a registry wallet case-insensitively (matches core matching)', async () => {
|
|
140
|
+
// Registry name and metadata name differ only by casing — core matches
|
|
141
|
+
// Solana names case-insensitively, so no duplicate legacy entry.
|
|
142
|
+
registryWallets = [standardWallet('Base Wallet')]
|
|
143
|
+
const wallets = await getSolanaWallets([
|
|
144
|
+
expectedWallet('BASE WALLET', 'coinbaseSolana')
|
|
145
|
+
])
|
|
146
|
+
expect(wallets).toHaveLength(1)
|
|
147
|
+
expect(wallets[0]!.adapter).not.toBeInstanceOf(MockLegacyAdapter)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('returns [] outside a browser (no window)', async () => {
|
|
151
|
+
vi.stubGlobal('window', undefined)
|
|
152
|
+
try {
|
|
153
|
+
const wallets = await getSolanaWallets([
|
|
154
|
+
expectedWallet('Base Wallet', 'coinbaseSolana')
|
|
155
|
+
])
|
|
156
|
+
expect(wallets).toEqual([])
|
|
157
|
+
} finally {
|
|
158
|
+
vi.unstubAllGlobals()
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('adds the legacy entry alongside other registry Solana wallets', async () => {
|
|
163
|
+
registryWallets = [standardWallet('Phantom')]
|
|
164
|
+
const wallets = await getSolanaWallets([
|
|
165
|
+
expectedWallet('Base Wallet', 'coinbaseSolana')
|
|
166
|
+
])
|
|
167
|
+
expect(wallets.map(w => w.name).sort()).toEqual(['Base Wallet', 'Phantom'])
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('keys a registry wallet uuid off its solana: chain, not chains[0]', async () => {
|
|
171
|
+
// Multi-chain wallet that lists a non-Solana chain first: the uuid must
|
|
172
|
+
// still derive from the solana: chain so it is stable regardless of the
|
|
173
|
+
// wallet's chain ordering.
|
|
174
|
+
registryWallets = [
|
|
175
|
+
standardWallet('Multi Wallet', ['eip155:1', SOLANA_MAINNET])
|
|
176
|
+
]
|
|
177
|
+
const wallets = await getSolanaWallets([])
|
|
178
|
+
|
|
179
|
+
expect(wallets).toHaveLength(1)
|
|
180
|
+
expect(wallets[0]!.uuid).toBe(
|
|
181
|
+
`multi-wallet-${SOLANA_MAINNET.toLowerCase()}`
|
|
182
|
+
)
|
|
183
|
+
expect(wallets[0]!.uuid).not.toContain('eip155')
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('is wallet-agnostic — works for any injectedId/name, not just Coinbase', async () => {
|
|
187
|
+
const wallets = await getSolanaWallets([
|
|
188
|
+
expectedWallet('Acme Wallet', 'acmeSolana')
|
|
189
|
+
])
|
|
190
|
+
expect(wallets[0]!.name).toBe('Acme Wallet')
|
|
191
|
+
expect((wallets[0]!.adapter as any).injectedId).toBe('acmeSolana')
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('names the legacy entry from the in-wallet provider when usingIntegratedBrowser', async () => {
|
|
195
|
+
// Coinbase/Base: extension solana name "Base Wallet", in-wallet "Base".
|
|
196
|
+
// Core matches the in-wallet name in the integrated-browser flow, so the
|
|
197
|
+
// synthetic entry must be named "Base" for the match to succeed.
|
|
198
|
+
const meta = {
|
|
199
|
+
extensionInjectedProvider: {
|
|
200
|
+
namespaceMetaData: {
|
|
201
|
+
solana: {
|
|
202
|
+
walletStandardName: 'Base Wallet',
|
|
203
|
+
injectedId: 'coinbaseSolana'
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
integratedBrowserInjectedProvider: {
|
|
208
|
+
namespaceMetaData: {
|
|
209
|
+
solana: { walletStandardName: 'Base', injectedId: 'coinbaseSolana' }
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
} as unknown as WalletMetadata
|
|
213
|
+
|
|
214
|
+
const wallets = await getSolanaWallets([meta], true)
|
|
215
|
+
expect(wallets).toHaveLength(1)
|
|
216
|
+
expect(wallets[0]!.name).toBe('Base')
|
|
217
|
+
expect(wallets[0]!.uuid).toBe(`base-${SOLANA_MAINNET.toLowerCase()}`)
|
|
218
|
+
expect((wallets[0]!.adapter as { name: string }).name).toBe('Base')
|
|
219
|
+
// injectedId is read from either provider (identical) — still resolves.
|
|
220
|
+
expect(getInjectedSolanaProvider).toHaveBeenCalledWith('coinbaseSolana')
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('resolves from the in-wallet provider when there is no extension metadata', async () => {
|
|
224
|
+
// Integrated-browser-only session: no extensionInjectedProvider at all, the
|
|
225
|
+
// injectedId + name live only on integratedBrowserInjectedProvider.
|
|
226
|
+
const meta = {
|
|
227
|
+
integratedBrowserInjectedProvider: {
|
|
228
|
+
namespaceMetaData: {
|
|
229
|
+
solana: { walletStandardName: 'Base', injectedId: 'coinbaseSolana' }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
} as unknown as WalletMetadata
|
|
233
|
+
|
|
234
|
+
const wallets = await getSolanaWallets([meta], true)
|
|
235
|
+
expect(wallets).toHaveLength(1)
|
|
236
|
+
expect(wallets[0]!.name).toBe('Base')
|
|
237
|
+
expect(getInjectedSolanaProvider).toHaveBeenCalledWith('coinbaseSolana')
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
it('produces NO entry in the in-wallet flow when the solana block lives only on the extension provider', async () => {
|
|
241
|
+
// Discovery names ONLY from the session-matched provider (mirrors core's
|
|
242
|
+
// pickProvider). With usingIntegratedBrowser and the solana block only on
|
|
243
|
+
// the extension provider, core would read the integrated provider and never
|
|
244
|
+
// match — so a cross-provider entry would be dead. We honestly skip it.
|
|
245
|
+
const wallets = await getSolanaWallets(
|
|
246
|
+
[expectedWallet('Base Wallet', 'coinbaseSolana')],
|
|
247
|
+
true
|
|
248
|
+
)
|
|
249
|
+
expect(wallets).toHaveLength(0)
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it('uses the extension name when not usingIntegratedBrowser even if an in-wallet name exists', async () => {
|
|
253
|
+
const meta = {
|
|
254
|
+
extensionInjectedProvider: {
|
|
255
|
+
namespaceMetaData: {
|
|
256
|
+
solana: {
|
|
257
|
+
walletStandardName: 'Base Wallet',
|
|
258
|
+
injectedId: 'coinbaseSolana'
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
integratedBrowserInjectedProvider: {
|
|
263
|
+
namespaceMetaData: {
|
|
264
|
+
solana: { walletStandardName: 'Base', injectedId: 'coinbaseSolana' }
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} as unknown as WalletMetadata
|
|
268
|
+
|
|
269
|
+
const wallets = await getSolanaWallets([meta], false)
|
|
270
|
+
expect(wallets[0]!.name).toBe('Base Wallet')
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
it('reports a discovery failure when the legacy global is present but the wrong shape', async () => {
|
|
274
|
+
// Global exists at window[injectedId] but isn't a valid Solana provider.
|
|
275
|
+
getInjectedSolanaProvider.mockReturnValue(undefined)
|
|
276
|
+
resolveInjectedProperty.mockReturnValue({ foo: 'bar' })
|
|
277
|
+
const onFailure = vi.fn()
|
|
278
|
+
|
|
279
|
+
const wallets = await getSolanaWallets(
|
|
280
|
+
[expectedWallet('Base Wallet', 'coinbaseSolana')],
|
|
281
|
+
false,
|
|
282
|
+
onFailure
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
expect(wallets).toHaveLength(0)
|
|
286
|
+
expect(onFailure).toHaveBeenCalledWith({
|
|
287
|
+
injectedId: 'coinbaseSolana',
|
|
288
|
+
walletName: 'Base Wallet'
|
|
289
|
+
})
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
it('does NOT report a failure when the legacy global is simply absent (not installed)', async () => {
|
|
293
|
+
getInjectedSolanaProvider.mockReturnValue(undefined)
|
|
294
|
+
resolveInjectedProperty.mockReturnValue(undefined)
|
|
295
|
+
const onFailure = vi.fn()
|
|
296
|
+
|
|
297
|
+
const wallets = await getSolanaWallets(
|
|
298
|
+
[expectedWallet('Base Wallet', 'coinbaseSolana')],
|
|
299
|
+
false,
|
|
300
|
+
onFailure
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
expect(wallets).toHaveLength(0)
|
|
304
|
+
expect(onFailure).not.toHaveBeenCalled()
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('does NOT report a failure when the legacy global is null', async () => {
|
|
308
|
+
getInjectedSolanaProvider.mockReturnValue(undefined)
|
|
309
|
+
resolveInjectedProperty.mockReturnValue(null)
|
|
310
|
+
const onFailure = vi.fn()
|
|
311
|
+
|
|
312
|
+
const wallets = await getSolanaWallets(
|
|
313
|
+
[expectedWallet('Base Wallet', 'coinbaseSolana')],
|
|
314
|
+
false,
|
|
315
|
+
onFailure
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
expect(wallets).toHaveLength(0)
|
|
319
|
+
expect(onFailure).not.toHaveBeenCalled()
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
it('does NOT report a failure when the legacy provider resolves normally', async () => {
|
|
323
|
+
const onFailure = vi.fn()
|
|
324
|
+
const wallets = await getSolanaWallets(
|
|
325
|
+
[expectedWallet('Base Wallet', 'coinbaseSolana')],
|
|
326
|
+
false,
|
|
327
|
+
onFailure
|
|
328
|
+
)
|
|
329
|
+
expect(wallets).toHaveLength(1)
|
|
330
|
+
expect(onFailure).not.toHaveBeenCalled()
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it('dedupes across multiple expected wallets with the same name', async () => {
|
|
334
|
+
const wallets = await getSolanaWallets([
|
|
335
|
+
expectedWallet('Base Wallet', 'coinbaseSolana'),
|
|
336
|
+
expectedWallet('Base Wallet', 'coinbaseSolana')
|
|
337
|
+
])
|
|
338
|
+
expect(wallets).toHaveLength(1)
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
it('uses the bridge list and skips the legacy fallback when framed', async () => {
|
|
342
|
+
;(window as any).UWCBridgeChildInitialized = true
|
|
343
|
+
;(window as any).walletStandardWallets = [
|
|
344
|
+
{ uuid: 'bridge-sol', name: 'Bridged Phantom', chains: [], features: [] }
|
|
345
|
+
]
|
|
346
|
+
const wallets = await getSolanaWallets([
|
|
347
|
+
expectedWallet('Base Wallet', 'coinbaseSolana')
|
|
348
|
+
])
|
|
349
|
+
expect(wallets.map(w => w.name)).toEqual(['Bridged Phantom'])
|
|
350
|
+
expect(getInjectedSolanaProvider).not.toHaveBeenCalled()
|
|
351
|
+
})
|
|
352
|
+
})
|
|
@@ -9,7 +9,26 @@ import { getWallets } from '@wallet-standard/app'
|
|
|
9
9
|
import { isWalletAdapterCompatibleStandardWallet } from '@solana/wallet-adapter-base'
|
|
10
10
|
import { StandardWalletAdapter } from '@solana/wallet-standard-wallet-adapter-base'
|
|
11
11
|
import type { Transaction } from '@solana/web3.js'
|
|
12
|
+
import type { WalletMetadata } from '@meshconnect/uwc-types'
|
|
13
|
+
import { solanaNetwork } from '@meshconnect/uwc-constants'
|
|
12
14
|
import { BRIDGE_WALLET_POLL_MS } from './bridge-poll'
|
|
15
|
+
import {
|
|
16
|
+
LegacyInjectedSolanaWalletAdapter,
|
|
17
|
+
getInjectedSolanaProvider,
|
|
18
|
+
resolveInjectedProperty
|
|
19
|
+
} from './legacy-injected-solana-adapter'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Telemetry sink for the legacy injected-Solana fallback. Fires only when a
|
|
23
|
+
* wallet declares `solana.injectedId` and a global exists at that path but is
|
|
24
|
+
* NOT a valid Solana provider (wrong method surface) — the actionable
|
|
25
|
+
* "the wallet changed its injected provider" signal. An absent global is a
|
|
26
|
+
* normal not-installed case and is intentionally not reported.
|
|
27
|
+
*/
|
|
28
|
+
export type LegacyInjectedSolanaDiscoveryFailure = (info: {
|
|
29
|
+
injectedId: string
|
|
30
|
+
walletName: string
|
|
31
|
+
}) => void
|
|
13
32
|
|
|
14
33
|
export interface ExtendedStandardWalletAdapter extends StandardWalletAdapter {
|
|
15
34
|
customFunctions: (
|
|
@@ -39,6 +58,11 @@ export interface ExtendedStandardWalletAdapter extends StandardWalletAdapter {
|
|
|
39
58
|
export type SolanaAdapter =
|
|
40
59
|
| ExtendedStandardWalletAdapter
|
|
41
60
|
| StandardWalletAdapter
|
|
61
|
+
// Legacy injected fallback (MFS-805): a BaseMessageSignerWalletAdapter, not a
|
|
62
|
+
// StandardWalletAdapter — it has no `.wallet` getter, so the sign path's
|
|
63
|
+
// `(adapter as StandardWalletAdapter).wallet` check falls through to the legacy
|
|
64
|
+
// branch. See legacy-injected-solana-adapter.ts.
|
|
65
|
+
| LegacyInjectedSolanaWalletAdapter
|
|
42
66
|
|
|
43
67
|
export interface WalletStandardInfo {
|
|
44
68
|
uuid: string
|
|
@@ -46,6 +70,12 @@ export interface WalletStandardInfo {
|
|
|
46
70
|
chains: string[]
|
|
47
71
|
features: string[]
|
|
48
72
|
adapter: SolanaAdapter | undefined
|
|
73
|
+
/**
|
|
74
|
+
* True only for entries produced by the legacy injected-Solana fallback (a
|
|
75
|
+
* `window[injectedId]` global), false/absent for Wallet Standard registry
|
|
76
|
+
* wallets. Lets detection report which discovery path matched (MFS-805).
|
|
77
|
+
*/
|
|
78
|
+
legacyInjected?: boolean
|
|
49
79
|
}
|
|
50
80
|
|
|
51
81
|
/**
|
|
@@ -98,7 +128,15 @@ async function pollForBridgeWallets(): Promise<WalletStandardInfo[]> {
|
|
|
98
128
|
/**
|
|
99
129
|
* Gets all available Solana wallets using Wallet Standard
|
|
100
130
|
*/
|
|
101
|
-
export async function getSolanaWallets(
|
|
131
|
+
export async function getSolanaWallets(
|
|
132
|
+
expectedWallets: WalletMetadata[] = [],
|
|
133
|
+
usingIntegratedBrowser = false,
|
|
134
|
+
onLegacyDiscoveryFailure?: LegacyInjectedSolanaDiscoveryFailure
|
|
135
|
+
): Promise<WalletStandardInfo[]> {
|
|
136
|
+
// No wallets to discover outside a browser (SSR / non-DOM) — every path below
|
|
137
|
+
// touches `window`.
|
|
138
|
+
if (typeof window === 'undefined') return []
|
|
139
|
+
|
|
102
140
|
// UWCBridgeChildInitialized is only initialized if app runs in an iframe. We can skip checking for bridge proxy providers when it's not necessary.
|
|
103
141
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
104
142
|
// @ts-ignore - window.UWCBridgeInitialized is set by the bridge
|
|
@@ -114,6 +152,9 @@ export async function getSolanaWallets(): Promise<WalletStandardInfo[]> {
|
|
|
114
152
|
const wallets = get()
|
|
115
153
|
|
|
116
154
|
const solanaWallets: WalletStandardInfo[] = []
|
|
155
|
+
// Lowercased names — dedupe must match core's case-insensitive Solana name
|
|
156
|
+
// matching, so a legacy entry can't slip past a registry wallet that differs
|
|
157
|
+
// only by casing.
|
|
117
158
|
const walletNames = new Set<string>()
|
|
118
159
|
|
|
119
160
|
// First, get wallets from Wallet Standard
|
|
@@ -126,17 +167,68 @@ export async function getSolanaWallets(): Promise<WalletStandardInfo[]> {
|
|
|
126
167
|
adapter = new StandardWalletAdapter({ wallet })
|
|
127
168
|
}
|
|
128
169
|
|
|
170
|
+
// Key the uuid on the wallet's first `solana:` chain (not `chains[0]`):
|
|
171
|
+
// multi-chain wallets may list a non-Solana chain first, which would make
|
|
172
|
+
// the id depend on chain ordering.
|
|
173
|
+
const solanaChain =
|
|
174
|
+
wallet.chains?.find(chain => chain.startsWith('solana:')) ||
|
|
175
|
+
wallet.chains?.[0] ||
|
|
176
|
+
'unknown'
|
|
177
|
+
|
|
129
178
|
solanaWallets.push({
|
|
130
|
-
uuid: generateWalletId(wallet),
|
|
179
|
+
uuid: generateWalletId(wallet.name, solanaChain),
|
|
131
180
|
name: wallet.name,
|
|
132
181
|
chains: (wallet.chains || []) as string[],
|
|
133
182
|
features: Object.keys(wallet.features),
|
|
134
183
|
adapter: adapter
|
|
135
184
|
})
|
|
136
|
-
walletNames.add(wallet.name)
|
|
185
|
+
walletNames.add(wallet.name.toLowerCase())
|
|
137
186
|
}
|
|
138
187
|
}
|
|
139
188
|
|
|
189
|
+
// Legacy injected-Solana fallback (MFS-805): wallets whose in-app browser
|
|
190
|
+
// exposes Solana only via a `window[injectedId]` global and never register with
|
|
191
|
+
// the Wallet Standard registry (first: Coinbase/Base Legacy mode). Metadata-
|
|
192
|
+
// driven, mirroring the EVM/TRON `injectedId` pattern — no wallet hardcoded.
|
|
193
|
+
for (const expected of expectedWallets) {
|
|
194
|
+
// Name + injectedId come ONLY from the provider core will match against —
|
|
195
|
+
// the session-matched one (mirrors applyDetectedWallet's `pickProvider`).
|
|
196
|
+
// No fallback to the other provider: core reads only `pickProvider(w)`, so a
|
|
197
|
+
// cross-provider entry (e.g. named from the extension while the session is
|
|
198
|
+
// the in-wallet browser) would be discovered but never marked `installed` —
|
|
199
|
+
// a dead entry. Skipping it is fail-closed and honest.
|
|
200
|
+
const sessionProvider = usingIntegratedBrowser
|
|
201
|
+
? expected.integratedBrowserInjectedProvider
|
|
202
|
+
: expected.extensionInjectedProvider
|
|
203
|
+
const solanaMeta = sessionProvider?.namespaceMetaData?.solana
|
|
204
|
+
const injectedId = solanaMeta?.injectedId
|
|
205
|
+
const name = solanaMeta?.walletStandardName
|
|
206
|
+
if (!injectedId || !name || walletNames.has(name.toLowerCase())) continue
|
|
207
|
+
if (!getInjectedSolanaProvider(injectedId)) {
|
|
208
|
+
// A global exists but isn't a valid Solana provider → actionable (the
|
|
209
|
+
// wallet changed its shape); an absent global is just not-installed.
|
|
210
|
+
if (resolveInjectedProperty(injectedId)) {
|
|
211
|
+
onLegacyDiscoveryFailure?.({ injectedId, walletName: name })
|
|
212
|
+
}
|
|
213
|
+
continue
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
solanaWallets.push({
|
|
217
|
+
uuid: generateWalletId(name, solanaNetwork.id),
|
|
218
|
+
name,
|
|
219
|
+
chains: [solanaNetwork.id],
|
|
220
|
+
features: [
|
|
221
|
+
'solana:signTransaction',
|
|
222
|
+
'solana:signAllTransactions',
|
|
223
|
+
'solana:signMessage',
|
|
224
|
+
'solana:signAndSendTransaction'
|
|
225
|
+
],
|
|
226
|
+
adapter: new LegacyInjectedSolanaWalletAdapter(injectedId, name),
|
|
227
|
+
legacyInjected: true
|
|
228
|
+
})
|
|
229
|
+
walletNames.add(name.toLowerCase())
|
|
230
|
+
}
|
|
231
|
+
|
|
140
232
|
return solanaWallets
|
|
141
233
|
}
|
|
142
234
|
|
|
@@ -151,9 +243,8 @@ function isSolanaWallet(wallet: Wallet): boolean {
|
|
|
151
243
|
}
|
|
152
244
|
|
|
153
245
|
/**
|
|
154
|
-
* Generate a unique ID for a wallet
|
|
246
|
+
* Generate a unique, stable ID for a wallet from its name + primary chain.
|
|
155
247
|
*/
|
|
156
|
-
function generateWalletId(
|
|
157
|
-
|
|
158
|
-
return `${wallet.name}-${chain}`.toLowerCase().replace(/\s+/g, '-')
|
|
248
|
+
function generateWalletId(name: string, chain: string): string {
|
|
249
|
+
return `${name}-${chain}`.toLowerCase().replace(/\s+/g, '-')
|
|
159
250
|
}
|