@meshconnect/uwc-injected-connector 0.20.3 → 0.22.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 +39 -2
- package/dist/injected-connector.d.ts.map +1 -1
- package/dist/injected-connector.js +170 -19
- package/dist/injected-connector.js.map +1 -1
- package/dist/services/connection-manager.d.ts +84 -5
- package/dist/services/connection-manager.d.ts.map +1 -1
- package/dist/services/connection-manager.js +172 -30
- package/dist/services/connection-manager.js.map +1 -1
- package/dist/services/ethereum/ethereum-transaction-builder.d.ts.map +1 -1
- package/dist/services/ethereum/ethereum-transaction-builder.js +3 -2
- package/dist/services/ethereum/ethereum-transaction-builder.js.map +1 -1
- package/dist/services/ethereum/ethereum-wallet-service.d.ts +86 -7
- package/dist/services/ethereum/ethereum-wallet-service.d.ts.map +1 -1
- package/dist/services/ethereum/ethereum-wallet-service.js +201 -28
- 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/dist/utils/step-reporter.d.ts +33 -0
- package/dist/utils/step-reporter.d.ts.map +1 -0
- package/dist/utils/step-reporter.js +54 -0
- package/dist/utils/step-reporter.js.map +1 -0
- package/dist/utils/with-deadline.d.ts +30 -0
- package/dist/utils/with-deadline.d.ts.map +1 -0
- package/dist/utils/with-deadline.js +67 -0
- package/dist/utils/with-deadline.js.map +1 -0
- 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 +574 -16
- package/src/injected-connector.ts +210 -23
- package/src/services/connection-manager.test.ts +338 -1
- package/src/services/connection-manager.ts +236 -41
- package/src/services/ethereum/ethereum-transaction-builder.test.ts +97 -0
- package/src/services/ethereum/ethereum-transaction-builder.ts +3 -2
- package/src/services/ethereum/ethereum-wallet-service.test.ts +495 -17
- package/src/services/ethereum/ethereum-wallet-service.ts +248 -32
- 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
- package/src/utils/step-reporter.test.ts +56 -0
- package/src/utils/step-reporter.ts +83 -0
- package/src/utils/with-deadline.test.ts +80 -0
- package/src/utils/with-deadline.ts +67 -0
|
@@ -6,8 +6,11 @@ import type {
|
|
|
6
6
|
ConnectorResult,
|
|
7
7
|
SwitchNetworkResult,
|
|
8
8
|
AvailableAddress,
|
|
9
|
-
SolanaMetadata
|
|
9
|
+
SolanaMetadata,
|
|
10
|
+
WalletStepInfo
|
|
10
11
|
} from '@meshconnect/uwc-types'
|
|
12
|
+
import { withDeadline } from '../utils/with-deadline'
|
|
13
|
+
import { createStepReporter, type StepReporter } from '../utils/step-reporter'
|
|
11
14
|
import { EthereumWalletService } from './ethereum/ethereum-wallet-service'
|
|
12
15
|
import { SolanaWalletService } from './solana/solana-wallet-service'
|
|
13
16
|
import { TronWalletService } from './tron/tron-wallet-service'
|
|
@@ -223,8 +226,53 @@ export interface ConnectionManagerOptions {
|
|
|
223
226
|
onWalletConnectionsReleased?:
|
|
224
227
|
| ((info: { namespaces: Namespace[] }) => void)
|
|
225
228
|
| undefined
|
|
229
|
+
/**
|
|
230
|
+
* Step-level telemetry sink (ONC-183) — see {@link WalletStepInfo}. Invoked
|
|
231
|
+
* once per named phase of a connect. Unlike the dedup'd sinks above this
|
|
232
|
+
* fires EVERY time: the point is per-attempt timing, so suppressing repeats
|
|
233
|
+
* would erase exactly the signal (a retry that hangs where the first didn't).
|
|
234
|
+
*/
|
|
235
|
+
onConnectStep?: ((info: WalletStepInfo) => void) | undefined
|
|
236
|
+
/**
|
|
237
|
+
* Per-namespace deadline (ms) for a best-effort SECONDARY address gather —
|
|
238
|
+
* see {@link ConnectionManager.checkAndAddOtherNamespaceAddresses}. `0`
|
|
239
|
+
* disables the bound (pre-ONC-183 behaviour).
|
|
240
|
+
*/
|
|
241
|
+
secondaryGatherTimeoutMs?: number | undefined
|
|
226
242
|
}
|
|
227
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Default per-namespace cap for a secondary address gather (ONC-183).
|
|
246
|
+
*
|
|
247
|
+
* These run AFTER the user has already authorized the target namespace, and a
|
|
248
|
+
* wallet that never answers one of them used to hold the entire connect open
|
|
249
|
+
* indefinitely — the dominant "connected but hung" class (MetaMask's Solana
|
|
250
|
+
* Snap prompt being the motivating case: EVM approved, Snap prompt abandoned,
|
|
251
|
+
* `connect()` pending forever).
|
|
252
|
+
*
|
|
253
|
+
* 15s is deliberately generous relative to the ~19s MEDIAN for a whole connect:
|
|
254
|
+
* this bounds one supplementary leg, not the user-facing approval, and the cost
|
|
255
|
+
* of firing early is a missing secondary address (the session still connects on
|
|
256
|
+
* the namespace the user asked for) while the cost of firing late is nil. Tune
|
|
257
|
+
* from the `walletStep` p99 once it has run in prod.
|
|
258
|
+
*/
|
|
259
|
+
export const DEFAULT_SECONDARY_GATHER_TIMEOUT_MS = 15_000
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* What a per-namespace secondary gather actually did, as reported UP to
|
|
263
|
+
* `gatherNamespace` for step telemetry.
|
|
264
|
+
*
|
|
265
|
+
* Necessary because each `checkAndAdd*Addresses` helper CATCHES its own wallet
|
|
266
|
+
* errors internally — that is the best-effort contract and it predates this
|
|
267
|
+
* telemetry. So the helper resolving normally does NOT mean the gather worked:
|
|
268
|
+
* a declined Solana Snap prompt is swallowed and resolves exactly like a clean
|
|
269
|
+
* no-op. Reporting `ok` off "the promise resolved" therefore mislabelled every
|
|
270
|
+
* user-declined secondary prompt as a success (ONC-183 review). The helpers
|
|
271
|
+
* return this instead so a swallowed failure is still reported as one, while
|
|
272
|
+
* the swallow keeps the connect alive.
|
|
273
|
+
*/
|
|
274
|
+
export type SecondaryGatherOutcome = 'ok' | 'failed'
|
|
275
|
+
|
|
228
276
|
export class ConnectionManager {
|
|
229
277
|
private currentNetworkId: string | null = null
|
|
230
278
|
|
|
@@ -248,6 +296,8 @@ export class ConnectionManager {
|
|
|
248
296
|
private readonly onWalletConnectionsReleased?:
|
|
249
297
|
| ((info: { namespaces: Namespace[] }) => void)
|
|
250
298
|
| undefined
|
|
299
|
+
private readonly steps: StepReporter
|
|
300
|
+
private readonly secondaryGatherTimeoutMs: number
|
|
251
301
|
|
|
252
302
|
constructor(
|
|
253
303
|
private ethereumService: EthereumWalletService,
|
|
@@ -262,6 +312,9 @@ export class ConnectionManager {
|
|
|
262
312
|
this.onSecondarySolanaConnectGathered =
|
|
263
313
|
options.onSecondarySolanaConnectGathered
|
|
264
314
|
this.onWalletConnectionsReleased = options.onWalletConnectionsReleased
|
|
315
|
+
this.steps = createStepReporter(options.onConnectStep)
|
|
316
|
+
this.secondaryGatherTimeoutMs =
|
|
317
|
+
options.secondaryGatherTimeoutMs ?? DEFAULT_SECONDARY_GATHER_TIMEOUT_MS
|
|
265
318
|
}
|
|
266
319
|
|
|
267
320
|
/** Report a gathered legacy-injectedId Solana address, once per injectedId x source. */
|
|
@@ -418,14 +471,18 @@ export class ConnectionManager {
|
|
|
418
471
|
if (walletUuid) {
|
|
419
472
|
const wallet = this.ethereumService.findWalletByUuid(walletUuid)
|
|
420
473
|
if (wallet?.provider) {
|
|
421
|
-
const accounts = await this.
|
|
422
|
-
|
|
474
|
+
const accounts = await this.steps.track(
|
|
475
|
+
'existingConnectionCheck',
|
|
476
|
+
'eip155',
|
|
477
|
+
() =>
|
|
478
|
+
this.ethereumService.checkExistingConnection(wallet.provider)
|
|
423
479
|
)
|
|
424
480
|
if (accounts && accounts.length > 0) {
|
|
425
481
|
currentAddress = accounts[0] || null
|
|
426
482
|
this.ethereumService.setConnectionState(
|
|
427
483
|
wallet.provider,
|
|
428
|
-
currentAddress
|
|
484
|
+
currentAddress,
|
|
485
|
+
walletUuid
|
|
429
486
|
)
|
|
430
487
|
}
|
|
431
488
|
}
|
|
@@ -561,7 +618,10 @@ export class ConnectionManager {
|
|
|
561
618
|
private async checkAndAddEthereumAddresses(
|
|
562
619
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
563
620
|
availableAddresses: AvailableAddress[]
|
|
564
|
-
): Promise<
|
|
621
|
+
): Promise<SecondaryGatherOutcome> {
|
|
622
|
+
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
623
|
+
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
624
|
+
let outcome: SecondaryGatherOutcome = 'ok'
|
|
565
625
|
let ethAccount = this.ethereumService.getAccount()
|
|
566
626
|
|
|
567
627
|
// If not connected, try to check existing connection
|
|
@@ -582,17 +642,23 @@ export class ConnectionManager {
|
|
|
582
642
|
? accounts[0]
|
|
583
643
|
: skipFramedSecondaryConnect()
|
|
584
644
|
? undefined
|
|
585
|
-
: await this.ethereumService.connect(
|
|
645
|
+
: await this.ethereumService.connect(
|
|
646
|
+
ethWallet.provider,
|
|
647
|
+
ethWalletUuid
|
|
648
|
+
)
|
|
586
649
|
if (ethAddress) {
|
|
587
650
|
ethAccount = ethAddress
|
|
588
651
|
this.ethereumService.setConnectionState(
|
|
589
652
|
ethWallet.provider,
|
|
590
|
-
ethAddress
|
|
653
|
+
ethAddress,
|
|
654
|
+
ethWalletUuid
|
|
591
655
|
)
|
|
592
656
|
}
|
|
593
657
|
} catch {
|
|
594
658
|
// EVM unavailable or the user declined the connect prompt —
|
|
595
|
-
// continue without it (same as the Solana/Tron/TON gathers)
|
|
659
|
+
// continue without it (same as the Solana/Tron/TON gathers), but
|
|
660
|
+
// record it so the step telemetry doesn't report this as 'ok'.
|
|
661
|
+
outcome = 'failed'
|
|
596
662
|
}
|
|
597
663
|
}
|
|
598
664
|
}
|
|
@@ -606,6 +672,7 @@ export class ConnectionManager {
|
|
|
606
672
|
)
|
|
607
673
|
availableAddresses.push(...ethAddresses)
|
|
608
674
|
}
|
|
675
|
+
return outcome
|
|
609
676
|
}
|
|
610
677
|
|
|
611
678
|
/**
|
|
@@ -614,7 +681,10 @@ export class ConnectionManager {
|
|
|
614
681
|
private async checkAndAddSolanaAddresses(
|
|
615
682
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
616
683
|
availableAddresses: AvailableAddress[]
|
|
617
|
-
): Promise<
|
|
684
|
+
): Promise<SecondaryGatherOutcome> {
|
|
685
|
+
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
686
|
+
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
687
|
+
let outcome: SecondaryGatherOutcome = 'ok'
|
|
618
688
|
let solanaAccount = this.solanaService.getAccount()
|
|
619
689
|
|
|
620
690
|
// If not connected, try to check existing connection
|
|
@@ -681,7 +751,10 @@ export class ConnectionManager {
|
|
|
681
751
|
)
|
|
682
752
|
}
|
|
683
753
|
} catch {
|
|
684
|
-
// Solana namespace not available
|
|
754
|
+
// Solana namespace not available (or the user declined the Snap
|
|
755
|
+
// prompt) — continue without it, but record the failure so the
|
|
756
|
+
// step telemetry doesn't report this as 'ok'.
|
|
757
|
+
outcome = 'failed'
|
|
685
758
|
}
|
|
686
759
|
}
|
|
687
760
|
}
|
|
@@ -695,6 +768,7 @@ export class ConnectionManager {
|
|
|
695
768
|
)
|
|
696
769
|
availableAddresses.push(...solanaAddresses)
|
|
697
770
|
}
|
|
771
|
+
return outcome
|
|
698
772
|
}
|
|
699
773
|
|
|
700
774
|
/**
|
|
@@ -703,7 +777,10 @@ export class ConnectionManager {
|
|
|
703
777
|
private async checkAndAddTronAddresses(
|
|
704
778
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
705
779
|
availableAddresses: AvailableAddress[]
|
|
706
|
-
): Promise<
|
|
780
|
+
): Promise<SecondaryGatherOutcome> {
|
|
781
|
+
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
782
|
+
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
783
|
+
let outcome: SecondaryGatherOutcome = 'ok'
|
|
707
784
|
let tronAccount = this.tronService.getAccount()
|
|
708
785
|
|
|
709
786
|
// If not connected, try to check existing connection
|
|
@@ -726,7 +803,9 @@ export class ConnectionManager {
|
|
|
726
803
|
this.tronService.setConnectionState(tronWallet.provider, address)
|
|
727
804
|
}
|
|
728
805
|
} catch {
|
|
729
|
-
// Tron namespace not available — continue without it
|
|
806
|
+
// Tron namespace not available — continue without it, but record
|
|
807
|
+
// the failure so the step telemetry doesn't report this as 'ok'.
|
|
808
|
+
outcome = 'failed'
|
|
730
809
|
}
|
|
731
810
|
}
|
|
732
811
|
}
|
|
@@ -740,6 +819,7 @@ export class ConnectionManager {
|
|
|
740
819
|
)
|
|
741
820
|
availableAddresses.push(...tronAddresses)
|
|
742
821
|
}
|
|
822
|
+
return outcome
|
|
743
823
|
}
|
|
744
824
|
|
|
745
825
|
/**
|
|
@@ -750,7 +830,10 @@ export class ConnectionManager {
|
|
|
750
830
|
private async checkAndAddTonAddresses(
|
|
751
831
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
752
832
|
availableAddresses: AvailableAddress[]
|
|
753
|
-
): Promise<
|
|
833
|
+
): Promise<SecondaryGatherOutcome> {
|
|
834
|
+
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
835
|
+
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
836
|
+
let outcome: SecondaryGatherOutcome = 'ok'
|
|
754
837
|
let tonAccount = this.tonService.getAccount()
|
|
755
838
|
|
|
756
839
|
if (!tonAccount) {
|
|
@@ -765,7 +848,9 @@ export class ConnectionManager {
|
|
|
765
848
|
const result = await this.tonService.connect(jsBridgeKey)
|
|
766
849
|
tonAccount = result.address
|
|
767
850
|
} catch {
|
|
768
|
-
// TON connection failed or was rejected — continue without TON
|
|
851
|
+
// TON connection failed or was rejected — continue without TON, but
|
|
852
|
+
// record the failure so the step telemetry doesn't report it as 'ok'.
|
|
853
|
+
outcome = 'failed'
|
|
769
854
|
}
|
|
770
855
|
}
|
|
771
856
|
}
|
|
@@ -777,11 +862,19 @@ export class ConnectionManager {
|
|
|
777
862
|
)
|
|
778
863
|
availableAddresses.push(...tonAddresses)
|
|
779
864
|
}
|
|
865
|
+
return outcome
|
|
780
866
|
}
|
|
781
867
|
|
|
782
868
|
/**
|
|
783
869
|
* After connecting one namespace, check and add addresses for all OTHER namespaces.
|
|
784
870
|
* E.g. after connecting Ethereum, also gather Solana, Tron, and TON addresses.
|
|
871
|
+
*
|
|
872
|
+
* Every leg is BEST-EFFORT and individually deadline-bounded (ONC-183). These
|
|
873
|
+
* run after the user has already authorized the target namespace, so a leg
|
|
874
|
+
* that never answers must cost its own address — not the whole connect. Each
|
|
875
|
+
* leg gets its OWN budget rather than one shared across all four: a shared
|
|
876
|
+
* budget would let a slow first leg silently starve the rest, turning one
|
|
877
|
+
* wallet's slowness into three missing addresses.
|
|
785
878
|
*/
|
|
786
879
|
private async checkAndAddOtherNamespaceAddresses(
|
|
787
880
|
connectedNamespace: 'eip155' | 'solana' | 'tron' | 'tvm',
|
|
@@ -789,30 +882,96 @@ export class ConnectionManager {
|
|
|
789
882
|
availableAddresses: AvailableAddress[]
|
|
790
883
|
): Promise<void> {
|
|
791
884
|
if (connectedNamespace !== 'eip155') {
|
|
792
|
-
await this.
|
|
885
|
+
await this.gatherNamespace('eip155', () =>
|
|
886
|
+
this.checkAndAddEthereumAddresses(provider, availableAddresses)
|
|
887
|
+
)
|
|
793
888
|
}
|
|
794
889
|
if (connectedNamespace !== 'solana') {
|
|
795
|
-
await this.
|
|
890
|
+
await this.gatherNamespace('solana', () =>
|
|
891
|
+
this.checkAndAddSolanaAddresses(provider, availableAddresses)
|
|
892
|
+
)
|
|
796
893
|
}
|
|
797
894
|
if (connectedNamespace !== 'tron') {
|
|
798
|
-
await this.
|
|
895
|
+
await this.gatherNamespace('tron', () =>
|
|
896
|
+
this.checkAndAddTronAddresses(provider, availableAddresses)
|
|
897
|
+
)
|
|
799
898
|
}
|
|
800
899
|
if (connectedNamespace !== 'tvm') {
|
|
801
|
-
await this.
|
|
900
|
+
await this.gatherNamespace('tvm', () =>
|
|
901
|
+
this.checkAndAddTonAddresses(provider, availableAddresses)
|
|
902
|
+
)
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Run one secondary-namespace gather under its deadline, reporting the
|
|
908
|
+
* outcome as a `secondaryGather` step.
|
|
909
|
+
*
|
|
910
|
+
* Swallows a rejection as well as a timeout: the per-namespace helpers below
|
|
911
|
+
* already catch their own wallet errors, so anything reaching here is an
|
|
912
|
+
* unexpected throw — and dropping one namespace's address is still the right
|
|
913
|
+
* degradation for a gather the user never asked for.
|
|
914
|
+
*
|
|
915
|
+
* The reported outcome comes from the helper's own
|
|
916
|
+
* {@link SecondaryGatherOutcome}, NOT from "did the promise resolve" — see
|
|
917
|
+
* that type for why those two are not the same thing.
|
|
918
|
+
*/
|
|
919
|
+
private async gatherNamespace(
|
|
920
|
+
namespace: Namespace,
|
|
921
|
+
gather: () => Promise<SecondaryGatherOutcome>
|
|
922
|
+
): Promise<void> {
|
|
923
|
+
const timeoutMs = this.secondaryGatherTimeoutMs
|
|
924
|
+
const start = Date.now()
|
|
925
|
+
let timedOut = false
|
|
926
|
+
try {
|
|
927
|
+
const outcome = await withDeadline(gather, timeoutMs, () => {
|
|
928
|
+
timedOut = true
|
|
929
|
+
this.steps.report({
|
|
930
|
+
step: 'secondaryGather',
|
|
931
|
+
outcome: 'timedOut',
|
|
932
|
+
durationMs: Date.now() - start,
|
|
933
|
+
namespace,
|
|
934
|
+
timeoutMs
|
|
935
|
+
})
|
|
936
|
+
})
|
|
937
|
+
if (!timedOut) {
|
|
938
|
+
this.steps.report({
|
|
939
|
+
step: 'secondaryGather',
|
|
940
|
+
// `withDeadline` resolves undefined only on the timeout path, which
|
|
941
|
+
// the `!timedOut` guard already excludes; treat a missing outcome as
|
|
942
|
+
// a failure rather than silently reporting success.
|
|
943
|
+
outcome: outcome ?? 'failed',
|
|
944
|
+
durationMs: Date.now() - start,
|
|
945
|
+
namespace
|
|
946
|
+
})
|
|
947
|
+
}
|
|
948
|
+
} catch {
|
|
949
|
+
this.steps.report({
|
|
950
|
+
step: 'secondaryGather',
|
|
951
|
+
outcome: 'failed',
|
|
952
|
+
durationMs: Date.now() - start,
|
|
953
|
+
namespace
|
|
954
|
+
})
|
|
802
955
|
}
|
|
803
956
|
}
|
|
804
957
|
|
|
805
958
|
/**
|
|
806
|
-
* Collect addresses from all currently-connected namespaces
|
|
807
|
-
*
|
|
808
|
-
*
|
|
959
|
+
* Collect addresses from all currently-connected namespaces using LIVE
|
|
960
|
+
* (freshly-read) accounts rather than each service's connect-time cache.
|
|
961
|
+
* Same networkId/namespace mapping, same shape, and same "only include
|
|
962
|
+
* namespaces with an address" rule as the connect-time gathers above,
|
|
963
|
+
* except it reads `getLiveAccount()` for eip155/solana/tron — closing
|
|
964
|
+
* the account-switch race where a stale cached address would otherwise
|
|
965
|
+
* flow into a post-switch verify/re-auth while signMessage reports the
|
|
966
|
+
* live account. TON has no live-read path (not the switch-staleness case
|
|
967
|
+
* here), so tvm keeps `getAccount()`.
|
|
809
968
|
*/
|
|
810
|
-
private
|
|
969
|
+
private async collectLiveConnectedAddresses(
|
|
811
970
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider
|
|
812
|
-
): AvailableAddress[] {
|
|
971
|
+
): Promise<AvailableAddress[]> {
|
|
813
972
|
const addresses: AvailableAddress[] = []
|
|
814
973
|
|
|
815
|
-
const ethAccount = this.ethereumService.
|
|
974
|
+
const ethAccount = await this.ethereumService.getLiveAccount()
|
|
816
975
|
if (ethAccount) {
|
|
817
976
|
addresses.push(
|
|
818
977
|
...this.ethereumService.buildAvailableAddresses(
|
|
@@ -822,7 +981,7 @@ export class ConnectionManager {
|
|
|
822
981
|
)
|
|
823
982
|
}
|
|
824
983
|
|
|
825
|
-
const solanaAccount = this.solanaService.
|
|
984
|
+
const solanaAccount = await this.solanaService.getLiveAccount()
|
|
826
985
|
if (solanaAccount) {
|
|
827
986
|
addresses.push(
|
|
828
987
|
...this.solanaService.buildAvailableAddresses(
|
|
@@ -832,7 +991,7 @@ export class ConnectionManager {
|
|
|
832
991
|
)
|
|
833
992
|
}
|
|
834
993
|
|
|
835
|
-
const tronAccount = this.tronService.
|
|
994
|
+
const tronAccount = await this.tronService.getLiveAccount()
|
|
836
995
|
if (tronAccount) {
|
|
837
996
|
addresses.push(
|
|
838
997
|
...this.tronService.buildAvailableAddresses(
|
|
@@ -863,20 +1022,34 @@ export class ConnectionManager {
|
|
|
863
1022
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider
|
|
864
1023
|
): Promise<ConnectorResult> {
|
|
865
1024
|
try {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
1025
|
+
// Provider detection is reported as its own step (ONC-183): both throws
|
|
1026
|
+
// below are "the wallet was never found", a failure class that is
|
|
1027
|
+
// indistinguishable from "the wallet never answered" once it collapses
|
|
1028
|
+
// into a single `walletFailed` terminal — and unlike a wallet hang it is
|
|
1029
|
+
// retryable without re-prompting the user.
|
|
1030
|
+
const wallet = await this.steps.track(
|
|
1031
|
+
'providerDetection',
|
|
1032
|
+
'eip155',
|
|
1033
|
+
() => {
|
|
1034
|
+
const uuid = provider.namespaceMetaData?.eip155?.detectedWallet?.uuid
|
|
1035
|
+
if (!uuid) {
|
|
1036
|
+
throw new Error(
|
|
1037
|
+
`${provider.namespaceMetaData.eip155?.eip155Name || provider.namespaceMetaData.eip155?.injectedId} wallet eip155 provider was not detected`
|
|
1038
|
+
)
|
|
1039
|
+
}
|
|
1040
|
+
const detected = this.ethereumService.findWalletByUuid(uuid)
|
|
1041
|
+
if (!detected || !detected.provider) {
|
|
1042
|
+
throw new Error(`Wallet provider not found for UUID: ${uuid}`)
|
|
1043
|
+
}
|
|
1044
|
+
return Promise.resolve({ uuid, provider: detected.provider })
|
|
1045
|
+
}
|
|
1046
|
+
)
|
|
878
1047
|
|
|
879
|
-
const address = await this.ethereumService.connect(
|
|
1048
|
+
const address = await this.ethereumService.connect(
|
|
1049
|
+
wallet.provider,
|
|
1050
|
+
wallet.uuid,
|
|
1051
|
+
info => this.steps.report(info)
|
|
1052
|
+
)
|
|
880
1053
|
this.currentNetworkId = network.id
|
|
881
1054
|
|
|
882
1055
|
const availableAddresses: AvailableAddress[] = []
|
|
@@ -1126,8 +1299,8 @@ export class ConnectionManager {
|
|
|
1126
1299
|
this.currentNetworkId = network.id
|
|
1127
1300
|
return {
|
|
1128
1301
|
networkId: network.id,
|
|
1129
|
-
address: this.
|
|
1130
|
-
availableAddresses: this.
|
|
1302
|
+
address: (await this.getLiveCurrentAccount()) || '',
|
|
1303
|
+
availableAddresses: await this.collectLiveConnectedAddresses(provider)
|
|
1131
1304
|
}
|
|
1132
1305
|
} catch (error) {
|
|
1133
1306
|
parseError(error)
|
|
@@ -1167,6 +1340,28 @@ export class ConnectionManager {
|
|
|
1167
1340
|
return null
|
|
1168
1341
|
}
|
|
1169
1342
|
|
|
1343
|
+
/**
|
|
1344
|
+
* Get the LIVE current account (freshly read from the wallet) based on the
|
|
1345
|
+
* current network. Mirrors `getCurrentAccount` but awaits the active
|
|
1346
|
+
* namespace's `getLiveAccount()` instead of returning the connect-time
|
|
1347
|
+
* cache — TON has no live-read path here, so tvm keeps `getAccount()`.
|
|
1348
|
+
*/
|
|
1349
|
+
private async getLiveCurrentAccount(): Promise<string | null> {
|
|
1350
|
+
if (this.currentNetworkId) {
|
|
1351
|
+
const namespace = this.currentNetworkId.split(':')[0]
|
|
1352
|
+
if (namespace === 'eip155') {
|
|
1353
|
+
return this.ethereumService.getLiveAccount()
|
|
1354
|
+
} else if (namespace === 'solana') {
|
|
1355
|
+
return this.solanaService.getLiveAccount()
|
|
1356
|
+
} else if (namespace === 'tron') {
|
|
1357
|
+
return this.tronService.getLiveAccount()
|
|
1358
|
+
} else if (namespace === 'tvm') {
|
|
1359
|
+
return this.tonService.getAccount()
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
return null
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1170
1365
|
/**
|
|
1171
1366
|
* Disconnect all
|
|
1172
1367
|
*/
|
|
@@ -249,4 +249,101 @@ describe('EthereumTransactionBuilder', () => {
|
|
|
249
249
|
expect(result.maxPriorityFeePerGas).toBe(BigInt(2000000000))
|
|
250
250
|
})
|
|
251
251
|
})
|
|
252
|
+
|
|
253
|
+
describe('value normalization', () => {
|
|
254
|
+
const oneEth = 1000000000000000000n
|
|
255
|
+
const from = '0x1234567890123456789012345678901234567890'
|
|
256
|
+
const to = '0x0987654321098765432109876543210987654321'
|
|
257
|
+
const cases: [string, bigint | string][] = [
|
|
258
|
+
['bigint', oneEth],
|
|
259
|
+
['decimal string', '1000000000000000000'],
|
|
260
|
+
['hex string', '0xde0b6b3a7640000']
|
|
261
|
+
]
|
|
262
|
+
|
|
263
|
+
it.each(cases)(
|
|
264
|
+
'contract-call value as %s normalizes to bigint',
|
|
265
|
+
async (_l, value) => {
|
|
266
|
+
const result = await builder.getContractTransaction({
|
|
267
|
+
from,
|
|
268
|
+
contractAddress: to,
|
|
269
|
+
abi: [
|
|
270
|
+
{
|
|
271
|
+
inputs: [],
|
|
272
|
+
name: 'deposit',
|
|
273
|
+
outputs: [],
|
|
274
|
+
stateMutability: 'payable',
|
|
275
|
+
type: 'function'
|
|
276
|
+
}
|
|
277
|
+
],
|
|
278
|
+
functionName: 'deposit',
|
|
279
|
+
args: [],
|
|
280
|
+
value
|
|
281
|
+
})
|
|
282
|
+
expect(result.value).toBe(oneEth)
|
|
283
|
+
}
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
it.each(cases)(
|
|
287
|
+
'data-transfer value as %s normalizes to bigint',
|
|
288
|
+
async (_l, value) => {
|
|
289
|
+
const result = await builder.getDataTransaction({
|
|
290
|
+
from,
|
|
291
|
+
to,
|
|
292
|
+
data: '0x',
|
|
293
|
+
chainId: '1',
|
|
294
|
+
value
|
|
295
|
+
})
|
|
296
|
+
expect(result.value).toBe(oneEth)
|
|
297
|
+
}
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
it('defaults a missing value to 0n', async () => {
|
|
301
|
+
const result = await builder.getDataTransaction({
|
|
302
|
+
from,
|
|
303
|
+
to,
|
|
304
|
+
data: '0x',
|
|
305
|
+
chainId: '1'
|
|
306
|
+
})
|
|
307
|
+
expect(result.value).toBe(0n)
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
it.each(['', ' ', 'abc', '1.5', '0x'])(
|
|
311
|
+
'rejects an invalid data-transfer value %j instead of coercing to 0',
|
|
312
|
+
async value => {
|
|
313
|
+
await expect(
|
|
314
|
+
builder.getDataTransaction({
|
|
315
|
+
from,
|
|
316
|
+
to,
|
|
317
|
+
data: '0x',
|
|
318
|
+
chainId: '1',
|
|
319
|
+
value
|
|
320
|
+
})
|
|
321
|
+
).rejects.toThrow(/Invalid EVM value/)
|
|
322
|
+
}
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
it.each(['', ' ', 'abc', '1.5', '0x'])(
|
|
326
|
+
'rejects an invalid contract-call value %j instead of coercing to 0',
|
|
327
|
+
async value => {
|
|
328
|
+
await expect(
|
|
329
|
+
builder.getContractTransaction({
|
|
330
|
+
from,
|
|
331
|
+
contractAddress: to,
|
|
332
|
+
abi: [
|
|
333
|
+
{
|
|
334
|
+
inputs: [],
|
|
335
|
+
name: 'deposit',
|
|
336
|
+
outputs: [],
|
|
337
|
+
stateMutability: 'payable',
|
|
338
|
+
type: 'function'
|
|
339
|
+
}
|
|
340
|
+
],
|
|
341
|
+
functionName: 'deposit',
|
|
342
|
+
args: [],
|
|
343
|
+
value
|
|
344
|
+
})
|
|
345
|
+
).rejects.toThrow(/Invalid EVM value/)
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
})
|
|
252
349
|
})
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
EVMTransactionParams,
|
|
7
7
|
EVMDataTransferRequest
|
|
8
8
|
} from '@meshconnect/uwc-types'
|
|
9
|
+
import { toEvmValueBigInt } from '@meshconnect/uwc-types'
|
|
9
10
|
import { parseError } from '../../utils/error-utils'
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -25,7 +26,7 @@ export class EthereumTransactionBuilder {
|
|
|
25
26
|
const txRequest: EVMTransactionParams = {
|
|
26
27
|
to: request.contractAddress,
|
|
27
28
|
data,
|
|
28
|
-
value: request.value
|
|
29
|
+
value: toEvmValueBigInt(request.value),
|
|
29
30
|
...this.formatGasConfig(request.gasConfig)
|
|
30
31
|
}
|
|
31
32
|
return txRequest
|
|
@@ -55,7 +56,7 @@ export class EthereumTransactionBuilder {
|
|
|
55
56
|
const txRequest: EVMTransactionParams = {
|
|
56
57
|
to: request.to,
|
|
57
58
|
data: request.data,
|
|
58
|
-
value: request.value
|
|
59
|
+
value: toEvmValueBigInt(request.value),
|
|
59
60
|
...this.formatGasConfig(request.gasConfig)
|
|
60
61
|
}
|
|
61
62
|
|