@meshconnect/uwc-injected-connector 0.20.3 → 0.21.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/eip6963-discovery.d.ts +13 -0
- package/dist/eip6963-discovery.d.ts.map +1 -1
- package/dist/eip6963-discovery.js +12 -3
- package/dist/eip6963-discovery.js.map +1 -1
- package/dist/injected-connector.d.ts +22 -2
- package/dist/injected-connector.d.ts.map +1 -1
- package/dist/injected-connector.js +125 -15
- package/dist/injected-connector.js.map +1 -1
- package/dist/services/connection-manager.d.ts +18 -5
- package/dist/services/connection-manager.d.ts.map +1 -1
- package/dist/services/connection-manager.js +43 -13
- package/dist/services/connection-manager.js.map +1 -1
- package/dist/services/ethereum/ethereum-wallet-service.d.ts +78 -6
- package/dist/services/ethereum/ethereum-wallet-service.d.ts.map +1 -1
- package/dist/services/ethereum/ethereum-wallet-service.js +187 -22
- package/dist/services/ethereum/ethereum-wallet-service.js.map +1 -1
- package/dist/services/solana/solana-wallet-service.d.ts +57 -0
- package/dist/services/solana/solana-wallet-service.d.ts.map +1 -1
- package/dist/services/solana/solana-wallet-service.js +118 -0
- package/dist/services/solana/solana-wallet-service.js.map +1 -1
- package/dist/services/ton/ton-wallet-service.d.ts +9 -0
- package/dist/services/ton/ton-wallet-service.d.ts.map +1 -1
- package/dist/services/ton/ton-wallet-service.js +15 -0
- package/dist/services/ton/ton-wallet-service.js.map +1 -1
- package/dist/services/tron/tron-wallet-service.d.ts +11 -0
- package/dist/services/tron/tron-wallet-service.d.ts.map +1 -1
- package/dist/services/tron/tron-wallet-service.js +21 -0
- package/dist/services/tron/tron-wallet-service.js.map +1 -1
- package/package.json +6 -6
- package/src/eip6963-discovery.test.ts +111 -2
- package/src/eip6963-discovery.ts +28 -4
- package/src/injected-connector.test.ts +477 -16
- package/src/injected-connector.ts +142 -18
- package/src/services/connection-manager.test.ts +104 -1
- package/src/services/connection-manager.ts +50 -14
- package/src/services/ethereum/ethereum-wallet-service.test.ts +495 -17
- package/src/services/ethereum/ethereum-wallet-service.ts +221 -25
- package/src/services/solana/solana-wallet-service.lifecycle.test.ts +156 -6
- package/src/services/solana/solana-wallet-service.reconnect.test.ts +175 -0
- package/src/services/solana/solana-wallet-service.ts +132 -0
- package/src/services/ton/ton-wallet-service.test.ts +25 -0
- package/src/services/ton/ton-wallet-service.ts +15 -0
- package/src/services/tron/tron-wallet-service.test.ts +45 -0
- package/src/services/tron/tron-wallet-service.ts +20 -0
- package/src/signSolanaTransactionBytes.test.ts +1 -1
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
TonNativeTransferRequest,
|
|
18
18
|
NetworkRpcMap,
|
|
19
19
|
EVMCapabilities,
|
|
20
|
-
|
|
20
|
+
SignatureResult,
|
|
21
21
|
EIP712TypedData,
|
|
22
22
|
WalletMetadata,
|
|
23
23
|
TonConnectConfig,
|
|
@@ -478,13 +478,69 @@ export class InjectedConnector implements Connector {
|
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
+
/**
|
|
482
|
+
* Real account-sync counterpart to `onLifecycleEvent` (see its doc for the
|
|
483
|
+
* routing rationale). `eip155` and `solana` (direct mode only — the
|
|
484
|
+
* solana service itself bails in the bridge, deferring to the bridge
|
|
485
|
+
* relay / polling) are wired; TON injected account-sync remains a
|
|
486
|
+
* follow-on, matching `onLifecycleEvent`'s own note (tron IS wired here
|
|
487
|
+
* via `tronConnector`).
|
|
488
|
+
*/
|
|
489
|
+
onAccountsChanged(
|
|
490
|
+
listener: (accounts: string[]) => void,
|
|
491
|
+
context: WalletLifecycleContext
|
|
492
|
+
): (() => void) | undefined {
|
|
493
|
+
switch (context.namespace) {
|
|
494
|
+
case 'eip155':
|
|
495
|
+
return this.ethereumService.onAccountsChanged(listener)
|
|
496
|
+
case 'solana':
|
|
497
|
+
return this.solanaService.onAccountsChanged(listener)
|
|
498
|
+
case 'tron':
|
|
499
|
+
return this.tronConnector?.onAccountsChanged?.(listener, context)
|
|
500
|
+
default:
|
|
501
|
+
return undefined
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Read the wallet's LIVE current address for a given namespace (see
|
|
507
|
+
* `Connector.getLiveAccount`). Routes to the SAME per-namespace live reads
|
|
508
|
+
* `signMessage` already uses (`ethereumService`/`solanaService`/
|
|
509
|
+
* `tronService`.`getLiveAccount()`, `tonService.getAccount()`) so switching
|
|
510
|
+
* an in-wallet account is visible without a fresh connect. For tron, prefer
|
|
511
|
+
* the Mesh-owned `tronConnector` (when configured) over the legacy
|
|
512
|
+
* `tronService`, mirroring how `signMessage`/`onAccountsChanged` already
|
|
513
|
+
* prioritize it. Never throws — swallows any underlying error as `null`.
|
|
514
|
+
*/
|
|
515
|
+
async getLiveAccount(namespace: Namespace): Promise<string | null> {
|
|
516
|
+
try {
|
|
517
|
+
switch (namespace) {
|
|
518
|
+
case 'eip155':
|
|
519
|
+
return await this.ethereumService.getLiveAccount()
|
|
520
|
+
case 'solana':
|
|
521
|
+
return await this.solanaService.getLiveAccount()
|
|
522
|
+
case 'tron':
|
|
523
|
+
return (
|
|
524
|
+
(await this.tronConnector?.getLiveAccount?.()) ??
|
|
525
|
+
(await this.tronService.getLiveAccount())
|
|
526
|
+
)
|
|
527
|
+
case 'tvm':
|
|
528
|
+
return this.tonService.getAccount() ?? null
|
|
529
|
+
default:
|
|
530
|
+
return null
|
|
531
|
+
}
|
|
532
|
+
} catch {
|
|
533
|
+
return null
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
481
537
|
/**
|
|
482
538
|
* Sign a message with the connected wallet
|
|
483
539
|
*/
|
|
484
540
|
async signMessage(
|
|
485
541
|
message: string,
|
|
486
542
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider
|
|
487
|
-
): Promise<
|
|
543
|
+
): Promise<SignatureResult> {
|
|
488
544
|
if (!provider) {
|
|
489
545
|
throw new Error('Provider is required for message signing')
|
|
490
546
|
}
|
|
@@ -510,44 +566,71 @@ export class InjectedConnector implements Connector {
|
|
|
510
566
|
const currentAddress = this.connectionManager.getCurrentAccount()
|
|
511
567
|
|
|
512
568
|
if (namespace === 'eip155') {
|
|
513
|
-
if (!currentAddress) {
|
|
514
|
-
throw new Error('No active wallet address for signing')
|
|
515
|
-
}
|
|
516
|
-
|
|
517
569
|
// Get the actual Ethereum provider
|
|
518
570
|
const ethProvider = this.ethereumService.getConnectedProvider()
|
|
519
571
|
if (!ethProvider) {
|
|
520
572
|
throw new Error('No connected Ethereum provider')
|
|
521
573
|
}
|
|
522
574
|
|
|
575
|
+
// `SignatureResult.address` MUST be the account that ACTUALLY signs — a
|
|
576
|
+
// downstream verify flow claims it to the backend. Read the LIVE selected
|
|
577
|
+
// account (reflects an in-wallet account switch) and use the SAME address
|
|
578
|
+
// as the `from` for personal_sign AND as the returned address, so
|
|
579
|
+
// claim == from == signer. Fall back to the connect-time cache only if the
|
|
580
|
+
// live read is unavailable; never claim an empty address.
|
|
581
|
+
const signerAddress =
|
|
582
|
+
(await this.ethereumService.getLiveAccount()) ?? currentAddress
|
|
583
|
+
if (!signerAddress) {
|
|
584
|
+
throw new Error('No active wallet address for signing')
|
|
585
|
+
}
|
|
586
|
+
|
|
523
587
|
const signature = await this.signatureService.signEthereumMessage(
|
|
524
588
|
message,
|
|
525
|
-
|
|
589
|
+
signerAddress,
|
|
526
590
|
ethProvider
|
|
527
591
|
)
|
|
528
592
|
return {
|
|
529
|
-
|
|
530
|
-
|
|
593
|
+
signature: {
|
|
594
|
+
type: 'standard',
|
|
595
|
+
signature: signature
|
|
596
|
+
},
|
|
597
|
+
address: signerAddress
|
|
531
598
|
}
|
|
532
599
|
} else if (namespace === 'solana') {
|
|
533
|
-
//
|
|
600
|
+
// Silently re-bind the adapter if a prior re-auth teardown cleared it, then
|
|
601
|
+
// read it SYNCHRONOUSLY — never `await` the adapter itself: in bridge mode
|
|
602
|
+
// it's a Comlink proxy, and awaiting that proxy forces Comlink to clone the
|
|
603
|
+
// (unserializable) adapter → "Unserializable return value".
|
|
604
|
+
await this.solanaService.ensureConnectedAdapter()
|
|
534
605
|
const solanaAdapter = this.solanaService.getConnectedAdapter()
|
|
535
606
|
if (!solanaAdapter) {
|
|
536
607
|
throw new Error('No connected Solana adapter')
|
|
537
608
|
}
|
|
538
609
|
|
|
610
|
+
// Claim the LIVE adapter public key (reflects an in-wallet account
|
|
611
|
+
// switch) rather than the connect-time cache, so the returned address is
|
|
612
|
+
// the account that ACTUALLY signed.
|
|
613
|
+
const signerAddress =
|
|
614
|
+
(await this.solanaService.getLiveAccount()) ?? currentAddress
|
|
615
|
+
if (!signerAddress) {
|
|
616
|
+
throw new Error('No active wallet address for signing')
|
|
617
|
+
}
|
|
618
|
+
|
|
539
619
|
const signature = await this.signatureService.signSolanaMessage(
|
|
540
620
|
message,
|
|
541
621
|
solanaAdapter
|
|
542
622
|
)
|
|
543
623
|
return {
|
|
544
|
-
|
|
545
|
-
|
|
624
|
+
signature: {
|
|
625
|
+
type: 'standard',
|
|
626
|
+
signature: signature
|
|
627
|
+
},
|
|
628
|
+
address: signerAddress
|
|
546
629
|
}
|
|
547
630
|
} else if (namespace === 'tron') {
|
|
548
631
|
if (this.tronConnector) {
|
|
549
|
-
// TronConnector.signMessage already returns a
|
|
550
|
-
// ({
|
|
632
|
+
// TronConnector.signMessage already returns a SignatureResult
|
|
633
|
+
// ({ signature, address }) — return it as-is, no re-wrap.
|
|
551
634
|
return await this.tronConnector.signMessage(message)
|
|
552
635
|
}
|
|
553
636
|
const tronProvider = this.tronService.getConnectedProvider()
|
|
@@ -555,16 +638,50 @@ export class InjectedConnector implements Connector {
|
|
|
555
638
|
throw new Error('No connected Tron provider')
|
|
556
639
|
}
|
|
557
640
|
|
|
641
|
+
// Claim the LIVE default address (reflects an in-wallet account switch);
|
|
642
|
+
// signMessageV2 signs with the wallet's current default address, so the
|
|
643
|
+
// returned address must match it, not the connect-time cache. Read it
|
|
644
|
+
// once before signing as a fallback for the throw-on-empty check below.
|
|
645
|
+
const preSignAddress =
|
|
646
|
+
(await this.tronService.getLiveAccount()) ?? currentAddress
|
|
647
|
+
|
|
558
648
|
const signature = await this.signatureService.signTronMessage(
|
|
559
649
|
message,
|
|
560
650
|
tronProvider
|
|
561
651
|
)
|
|
652
|
+
|
|
653
|
+
// signMessageV2 takes no address param — it implicitly signs with
|
|
654
|
+
// tronWeb.defaultAddress at execution time. Re-read the live address
|
|
655
|
+
// AFTER signing resolves (rather than reusing the pre-sign read) so
|
|
656
|
+
// the returned address reflects the account active at sign
|
|
657
|
+
// completion, not a stale snapshot from before the `await`. This
|
|
658
|
+
// closes the same account-switch TOCTOU window that eip155/solana
|
|
659
|
+
// avoid by pinning an explicit signer address.
|
|
660
|
+
const signerAddress =
|
|
661
|
+
(await this.tronService.getLiveAccount()) ?? preSignAddress
|
|
662
|
+
if (!signerAddress) {
|
|
663
|
+
throw new Error('No active wallet address for signing')
|
|
664
|
+
}
|
|
665
|
+
|
|
562
666
|
return {
|
|
563
|
-
|
|
564
|
-
|
|
667
|
+
signature: {
|
|
668
|
+
type: 'standard',
|
|
669
|
+
signature: signature
|
|
670
|
+
},
|
|
671
|
+
address: signerAddress
|
|
565
672
|
}
|
|
566
673
|
} else if (namespace === 'tvm') {
|
|
567
|
-
|
|
674
|
+
// For TON the signer address lives on the TON service (its own bridge
|
|
675
|
+
// account), not the connection manager's active account.
|
|
676
|
+
const tonAddress = this.tonService.getAccount()
|
|
677
|
+
if (!tonAddress) {
|
|
678
|
+
throw new Error('No active wallet address for signing')
|
|
679
|
+
}
|
|
680
|
+
const signature = await this.tonService.signMessage(message)
|
|
681
|
+
return {
|
|
682
|
+
signature,
|
|
683
|
+
address: tonAddress
|
|
684
|
+
}
|
|
568
685
|
} else {
|
|
569
686
|
throw new Error(`Signing not supported for namespace: ${namespace}`)
|
|
570
687
|
}
|
|
@@ -646,7 +763,10 @@ export class InjectedConnector implements Connector {
|
|
|
646
763
|
ethProvider
|
|
647
764
|
)
|
|
648
765
|
} else if (namespace === 'solana') {
|
|
649
|
-
//
|
|
766
|
+
// Silently re-bind if cleared, then read the adapter SYNCHRONOUSLY — never
|
|
767
|
+
// `await` the adapter proxy (bridge-mode Comlink clone → "Unserializable
|
|
768
|
+
// return value").
|
|
769
|
+
await this.solanaService.ensureConnectedAdapter()
|
|
650
770
|
const solanaAdapter = this.solanaService.getConnectedAdapter()
|
|
651
771
|
if (!solanaAdapter) {
|
|
652
772
|
throw new Error('No connected Solana adapter')
|
|
@@ -715,6 +835,10 @@ export class InjectedConnector implements Connector {
|
|
|
715
835
|
)
|
|
716
836
|
}
|
|
717
837
|
|
|
838
|
+
// Silently re-bind if cleared, then read the adapter SYNCHRONOUSLY — never
|
|
839
|
+
// `await` the adapter proxy (bridge-mode Comlink clone → "Unserializable
|
|
840
|
+
// return value").
|
|
841
|
+
await this.solanaService.ensureConnectedAdapter()
|
|
718
842
|
const solanaAdapter = this.solanaService.getConnectedAdapter()
|
|
719
843
|
if (!solanaAdapter) {
|
|
720
844
|
throw new Error('No connected Solana adapter')
|
|
@@ -35,6 +35,7 @@ function makeNetwork(id: string, namespace: string): Network {
|
|
|
35
35
|
function makeEthService() {
|
|
36
36
|
return {
|
|
37
37
|
getAccount: vi.fn().mockReturnValue(null),
|
|
38
|
+
getLiveAccount: vi.fn().mockResolvedValue(null),
|
|
38
39
|
findWalletByUuid: vi.fn().mockReturnValue(null),
|
|
39
40
|
checkExistingConnection: vi.fn().mockResolvedValue(null),
|
|
40
41
|
connect: vi.fn().mockResolvedValue('0xABC'),
|
|
@@ -55,6 +56,7 @@ function makeEthService() {
|
|
|
55
56
|
function makeSolanaService() {
|
|
56
57
|
return {
|
|
57
58
|
getAccount: vi.fn().mockReturnValue(null),
|
|
59
|
+
getLiveAccount: vi.fn().mockResolvedValue(null),
|
|
58
60
|
findWalletByUuid: vi.fn().mockReturnValue(null),
|
|
59
61
|
checkExistingConnection: vi.fn().mockResolvedValue(null),
|
|
60
62
|
connect: vi.fn().mockResolvedValue('SolAddr1'),
|
|
@@ -74,6 +76,7 @@ function makeSolanaService() {
|
|
|
74
76
|
function makeTronService() {
|
|
75
77
|
return {
|
|
76
78
|
getAccount: vi.fn().mockReturnValue(null),
|
|
79
|
+
getLiveAccount: vi.fn().mockResolvedValue(null),
|
|
77
80
|
findWalletByUuid: vi.fn().mockReturnValue(null),
|
|
78
81
|
checkExistingConnection: vi.fn().mockResolvedValue(null),
|
|
79
82
|
connect: vi.fn().mockResolvedValue('TronAddr1'),
|
|
@@ -1114,9 +1117,13 @@ describe('ConnectionManager — wallet switch releases the other wallet’s conn
|
|
|
1114
1117
|
walletBProvider
|
|
1115
1118
|
)
|
|
1116
1119
|
expect(result.address).toBe('0xBBB')
|
|
1120
|
+
// Third arg is the connected wallet's uuid — captured for provenance /
|
|
1121
|
+
// account-sync (MFS-778 branch's `setConnectionState(provider, account,
|
|
1122
|
+
// uuid)`), which post-dates this main-side test.
|
|
1117
1123
|
expect(ethService.setConnectionState).toHaveBeenCalledWith(
|
|
1118
1124
|
walletBProvider,
|
|
1119
|
-
'0xBBB'
|
|
1125
|
+
'0xBBB',
|
|
1126
|
+
'wallet-b-eip155'
|
|
1120
1127
|
)
|
|
1121
1128
|
// The release is surfaced to the telemetry sink with the namespaces dropped.
|
|
1122
1129
|
expect(onWalletConnectionsReleased).toHaveBeenCalledTimes(1)
|
|
@@ -1210,3 +1217,99 @@ describe('ConnectionManager — wallet switch releases the other wallet’s conn
|
|
|
1210
1217
|
expect(onWalletConnectionsReleased).not.toHaveBeenCalled()
|
|
1211
1218
|
})
|
|
1212
1219
|
})
|
|
1220
|
+
|
|
1221
|
+
// Root cause: on an in-wallet account switch, switchNetwork's return used to
|
|
1222
|
+
// read the frozen connect-time cache (service.getAccount()) for both `address`
|
|
1223
|
+
// and `availableAddresses`, so a post-switch verify/re-auth got bound to the
|
|
1224
|
+
// STALE account while signMessage reported the LIVE one ("Wallet mismatch").
|
|
1225
|
+
// switchNetwork must return LIVE reads (service.getLiveAccount()) instead.
|
|
1226
|
+
describe('ConnectionManager — switchNetwork returns LIVE addresses (not connect-time cache)', () => {
|
|
1227
|
+
let ethService: ReturnType<typeof makeEthService>
|
|
1228
|
+
let solanaService: ReturnType<typeof makeSolanaService>
|
|
1229
|
+
let tronService: ReturnType<typeof makeTronService>
|
|
1230
|
+
let tonService: ReturnType<typeof makeTonService>
|
|
1231
|
+
let manager: ConnectionManager
|
|
1232
|
+
|
|
1233
|
+
beforeEach(() => {
|
|
1234
|
+
ethService = makeEthService()
|
|
1235
|
+
solanaService = makeSolanaService()
|
|
1236
|
+
tronService = makeTronService()
|
|
1237
|
+
tonService = makeTonService()
|
|
1238
|
+
manager = new ConnectionManager(
|
|
1239
|
+
ethService as any,
|
|
1240
|
+
solanaService as any,
|
|
1241
|
+
tronService as any,
|
|
1242
|
+
tonService as any
|
|
1243
|
+
)
|
|
1244
|
+
})
|
|
1245
|
+
|
|
1246
|
+
it('returns the LIVE eip155 address, not the stale connect-time cache, on a same-namespace switch', async () => {
|
|
1247
|
+
// Already connected on eip155 (same-namespace switch path).
|
|
1248
|
+
ethService.getConnectedProvider.mockReturnValue({})
|
|
1249
|
+
// Cached/connect-time account is stale...
|
|
1250
|
+
ethService.getAccount.mockReturnValue('0xOLD')
|
|
1251
|
+
// ...but the wallet's live account has since switched.
|
|
1252
|
+
ethService.getLiveAccount.mockResolvedValue('0xNEW')
|
|
1253
|
+
|
|
1254
|
+
const provider = makeProvider({ eip155: {} })
|
|
1255
|
+
|
|
1256
|
+
const result = await manager.switchNetwork(
|
|
1257
|
+
makeNetwork('eip155:1', 'eip155'),
|
|
1258
|
+
provider
|
|
1259
|
+
)
|
|
1260
|
+
|
|
1261
|
+
expect(result.address).toBe('0xNEW')
|
|
1262
|
+
expect(result.availableAddresses).toEqual([
|
|
1263
|
+
{ address: '0xNEW', networkId: 'eip155:1' }
|
|
1264
|
+
])
|
|
1265
|
+
// The stale cache must not leak into the result.
|
|
1266
|
+
expect(result.availableAddresses.some(a => a.address === '0xOLD')).toBe(
|
|
1267
|
+
false
|
|
1268
|
+
)
|
|
1269
|
+
})
|
|
1270
|
+
|
|
1271
|
+
it('omits a namespace whose live account is null, even if it has a cached account (parity with the cached collector)', async () => {
|
|
1272
|
+
ethService.getConnectedProvider.mockReturnValue({})
|
|
1273
|
+
ethService.getAccount.mockReturnValue('0xOLD')
|
|
1274
|
+
ethService.getLiveAccount.mockResolvedValue('0xNEW')
|
|
1275
|
+
|
|
1276
|
+
// Solana was connected in this session (has a cached account)...
|
|
1277
|
+
solanaService.getAccount.mockReturnValue('SolCachedAddr')
|
|
1278
|
+
// ...but its live read now resolves null (e.g. disconnected wallet).
|
|
1279
|
+
solanaService.getLiveAccount.mockResolvedValue(null)
|
|
1280
|
+
|
|
1281
|
+
const provider = makeProvider({ eip155: {}, solana: {} })
|
|
1282
|
+
|
|
1283
|
+
const result = await manager.switchNetwork(
|
|
1284
|
+
makeNetwork('eip155:1', 'eip155'),
|
|
1285
|
+
provider
|
|
1286
|
+
)
|
|
1287
|
+
|
|
1288
|
+
const namespaces = result.availableAddresses.map(
|
|
1289
|
+
a => a.networkId.split(':')[0]
|
|
1290
|
+
)
|
|
1291
|
+
expect(namespaces).toContain('eip155')
|
|
1292
|
+
expect(namespaces).not.toContain('solana')
|
|
1293
|
+
expect(
|
|
1294
|
+
result.availableAddresses.some(a => a.address === 'SolCachedAddr')
|
|
1295
|
+
).toBe(false)
|
|
1296
|
+
})
|
|
1297
|
+
|
|
1298
|
+
it('behaves identically to the cached path when the live account equals the cached account (no regression)', async () => {
|
|
1299
|
+
ethService.getConnectedProvider.mockReturnValue({})
|
|
1300
|
+
ethService.getAccount.mockReturnValue('0xSAME')
|
|
1301
|
+
ethService.getLiveAccount.mockResolvedValue('0xSAME')
|
|
1302
|
+
|
|
1303
|
+
const provider = makeProvider({ eip155: {} })
|
|
1304
|
+
|
|
1305
|
+
const result = await manager.switchNetwork(
|
|
1306
|
+
makeNetwork('eip155:1', 'eip155'),
|
|
1307
|
+
provider
|
|
1308
|
+
)
|
|
1309
|
+
|
|
1310
|
+
expect(result.address).toBe('0xSAME')
|
|
1311
|
+
expect(result.availableAddresses).toEqual([
|
|
1312
|
+
{ address: '0xSAME', networkId: 'eip155:1' }
|
|
1313
|
+
])
|
|
1314
|
+
})
|
|
1315
|
+
})
|
|
@@ -425,7 +425,8 @@ export class ConnectionManager {
|
|
|
425
425
|
currentAddress = accounts[0] || null
|
|
426
426
|
this.ethereumService.setConnectionState(
|
|
427
427
|
wallet.provider,
|
|
428
|
-
currentAddress
|
|
428
|
+
currentAddress,
|
|
429
|
+
walletUuid
|
|
429
430
|
)
|
|
430
431
|
}
|
|
431
432
|
}
|
|
@@ -582,12 +583,16 @@ export class ConnectionManager {
|
|
|
582
583
|
? accounts[0]
|
|
583
584
|
: skipFramedSecondaryConnect()
|
|
584
585
|
? undefined
|
|
585
|
-
: await this.ethereumService.connect(
|
|
586
|
+
: await this.ethereumService.connect(
|
|
587
|
+
ethWallet.provider,
|
|
588
|
+
ethWalletUuid
|
|
589
|
+
)
|
|
586
590
|
if (ethAddress) {
|
|
587
591
|
ethAccount = ethAddress
|
|
588
592
|
this.ethereumService.setConnectionState(
|
|
589
593
|
ethWallet.provider,
|
|
590
|
-
ethAddress
|
|
594
|
+
ethAddress,
|
|
595
|
+
ethWalletUuid
|
|
591
596
|
)
|
|
592
597
|
}
|
|
593
598
|
} catch {
|
|
@@ -803,16 +808,22 @@ export class ConnectionManager {
|
|
|
803
808
|
}
|
|
804
809
|
|
|
805
810
|
/**
|
|
806
|
-
* Collect addresses from all currently-connected namespaces
|
|
807
|
-
*
|
|
808
|
-
*
|
|
811
|
+
* Collect addresses from all currently-connected namespaces using LIVE
|
|
812
|
+
* (freshly-read) accounts rather than each service's connect-time cache.
|
|
813
|
+
* Same networkId/namespace mapping, same shape, and same "only include
|
|
814
|
+
* namespaces with an address" rule as the connect-time gathers above,
|
|
815
|
+
* except it reads `getLiveAccount()` for eip155/solana/tron — closing
|
|
816
|
+
* the account-switch race where a stale cached address would otherwise
|
|
817
|
+
* flow into a post-switch verify/re-auth while signMessage reports the
|
|
818
|
+
* live account. TON has no live-read path (not the switch-staleness case
|
|
819
|
+
* here), so tvm keeps `getAccount()`.
|
|
809
820
|
*/
|
|
810
|
-
private
|
|
821
|
+
private async collectLiveConnectedAddresses(
|
|
811
822
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider
|
|
812
|
-
): AvailableAddress[] {
|
|
823
|
+
): Promise<AvailableAddress[]> {
|
|
813
824
|
const addresses: AvailableAddress[] = []
|
|
814
825
|
|
|
815
|
-
const ethAccount = this.ethereumService.
|
|
826
|
+
const ethAccount = await this.ethereumService.getLiveAccount()
|
|
816
827
|
if (ethAccount) {
|
|
817
828
|
addresses.push(
|
|
818
829
|
...this.ethereumService.buildAvailableAddresses(
|
|
@@ -822,7 +833,7 @@ export class ConnectionManager {
|
|
|
822
833
|
)
|
|
823
834
|
}
|
|
824
835
|
|
|
825
|
-
const solanaAccount = this.solanaService.
|
|
836
|
+
const solanaAccount = await this.solanaService.getLiveAccount()
|
|
826
837
|
if (solanaAccount) {
|
|
827
838
|
addresses.push(
|
|
828
839
|
...this.solanaService.buildAvailableAddresses(
|
|
@@ -832,7 +843,7 @@ export class ConnectionManager {
|
|
|
832
843
|
)
|
|
833
844
|
}
|
|
834
845
|
|
|
835
|
-
const tronAccount = this.tronService.
|
|
846
|
+
const tronAccount = await this.tronService.getLiveAccount()
|
|
836
847
|
if (tronAccount) {
|
|
837
848
|
addresses.push(
|
|
838
849
|
...this.tronService.buildAvailableAddresses(
|
|
@@ -876,7 +887,10 @@ export class ConnectionManager {
|
|
|
876
887
|
throw new Error(`Wallet provider not found for UUID: ${walletUuid}`)
|
|
877
888
|
}
|
|
878
889
|
|
|
879
|
-
const address = await this.ethereumService.connect(
|
|
890
|
+
const address = await this.ethereumService.connect(
|
|
891
|
+
wallet.provider,
|
|
892
|
+
walletUuid
|
|
893
|
+
)
|
|
880
894
|
this.currentNetworkId = network.id
|
|
881
895
|
|
|
882
896
|
const availableAddresses: AvailableAddress[] = []
|
|
@@ -1126,8 +1140,8 @@ export class ConnectionManager {
|
|
|
1126
1140
|
this.currentNetworkId = network.id
|
|
1127
1141
|
return {
|
|
1128
1142
|
networkId: network.id,
|
|
1129
|
-
address: this.
|
|
1130
|
-
availableAddresses: this.
|
|
1143
|
+
address: (await this.getLiveCurrentAccount()) || '',
|
|
1144
|
+
availableAddresses: await this.collectLiveConnectedAddresses(provider)
|
|
1131
1145
|
}
|
|
1132
1146
|
} catch (error) {
|
|
1133
1147
|
parseError(error)
|
|
@@ -1167,6 +1181,28 @@ export class ConnectionManager {
|
|
|
1167
1181
|
return null
|
|
1168
1182
|
}
|
|
1169
1183
|
|
|
1184
|
+
/**
|
|
1185
|
+
* Get the LIVE current account (freshly read from the wallet) based on the
|
|
1186
|
+
* current network. Mirrors `getCurrentAccount` but awaits the active
|
|
1187
|
+
* namespace's `getLiveAccount()` instead of returning the connect-time
|
|
1188
|
+
* cache — TON has no live-read path here, so tvm keeps `getAccount()`.
|
|
1189
|
+
*/
|
|
1190
|
+
private async getLiveCurrentAccount(): Promise<string | null> {
|
|
1191
|
+
if (this.currentNetworkId) {
|
|
1192
|
+
const namespace = this.currentNetworkId.split(':')[0]
|
|
1193
|
+
if (namespace === 'eip155') {
|
|
1194
|
+
return this.ethereumService.getLiveAccount()
|
|
1195
|
+
} else if (namespace === 'solana') {
|
|
1196
|
+
return this.solanaService.getLiveAccount()
|
|
1197
|
+
} else if (namespace === 'tron') {
|
|
1198
|
+
return this.tronService.getLiveAccount()
|
|
1199
|
+
} else if (namespace === 'tvm') {
|
|
1200
|
+
return this.tonService.getAccount()
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return null
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1170
1206
|
/**
|
|
1171
1207
|
* Disconnect all
|
|
1172
1208
|
*/
|