@meshconnect/uwc-injected-connector 0.27.5 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/injected-connector.d.ts.map +1 -1
- package/dist/injected-connector.js +62 -47
- package/dist/injected-connector.js.map +1 -1
- package/dist/services/connection-manager.d.ts +17 -13
- package/dist/services/connection-manager.d.ts.map +1 -1
- package/dist/services/connection-manager.js +93 -65
- package/dist/services/connection-manager.js.map +1 -1
- package/dist/services/solana/solana-wallet-service.d.ts +2 -0
- package/dist/services/solana/solana-wallet-service.d.ts.map +1 -1
- package/dist/services/solana/solana-wallet-service.js +1 -0
- package/dist/services/solana/solana-wallet-service.js.map +1 -1
- package/dist/services/ton/ton-wallet-service.d.ts +7 -1
- package/dist/services/ton/ton-wallet-service.d.ts.map +1 -1
- package/dist/services/ton/ton-wallet-service.js +21 -1
- package/dist/services/ton/ton-wallet-service.js.map +1 -1
- package/dist/utils/secondary-prompt-gap.d.ts +47 -0
- package/dist/utils/secondary-prompt-gap.d.ts.map +1 -0
- package/dist/utils/secondary-prompt-gap.js +65 -0
- package/dist/utils/secondary-prompt-gap.js.map +1 -0
- package/package.json +6 -6
- package/src/injected-connector.test.ts +374 -7
- package/src/injected-connector.ts +100 -55
- package/src/services/connection-manager.test.ts +841 -171
- package/src/services/connection-manager.ts +157 -86
- package/src/services/solana/solana-wallet-service.check-existing.test.ts +24 -0
- package/src/services/solana/solana-wallet-service.ts +6 -1
- package/src/services/ton/ton-wallet-service.test.ts +69 -0
- package/src/services/ton/ton-wallet-service.ts +22 -1
- package/src/utils/secondary-prompt-gap.test.ts +288 -0
- package/src/utils/secondary-prompt-gap.ts +95 -0
|
@@ -59,7 +59,11 @@ import type {
|
|
|
59
59
|
SecondarySolanaConnectSkippedInfo,
|
|
60
60
|
SecondarySolanaConnectGatheredInfo
|
|
61
61
|
} from './services/connection-manager'
|
|
62
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
markPrompted,
|
|
64
|
+
runSecondaryLeg,
|
|
65
|
+
waitBeforeSecondaryPrompt
|
|
66
|
+
} from './utils/secondary-prompt-gap'
|
|
63
67
|
import { gatherFailure } from './utils/gather-failure'
|
|
64
68
|
import { createStepReporter, type StepReporter } from './utils/step-reporter'
|
|
65
69
|
import { SignatureService } from './services/signature-service'
|
|
@@ -400,6 +404,7 @@ export class InjectedConnector implements Connector {
|
|
|
400
404
|
const targetNamespace = network.namespace
|
|
401
405
|
const requiredAddresses = options?.requiredAddresses
|
|
402
406
|
const silentOnly = options?.silentOnly === true
|
|
407
|
+
const promptGapMs = options?.secondaryPromptGapMs ?? 0
|
|
403
408
|
|
|
404
409
|
// Check if we're already connected — bip122 now flows through the same
|
|
405
410
|
// shared plumbing as every other namespace (non-prompting probe against
|
|
@@ -413,13 +418,16 @@ export class InjectedConnector implements Connector {
|
|
|
413
418
|
// Begun first, so an earlier attempt still running stops being live; its
|
|
414
419
|
// generation is carried to the primary request (ONC-2390).
|
|
415
420
|
const attempt = this.connectionManager.beginAttempt()
|
|
416
|
-
const {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
421
|
+
const {
|
|
422
|
+
address: existingAddress,
|
|
423
|
+
availableAddresses,
|
|
424
|
+
secondaryPrompted
|
|
425
|
+
} = await this.connectionManager.checkExistingConnections(
|
|
426
|
+
targetNamespace,
|
|
427
|
+
provider,
|
|
428
|
+
requiredAddresses,
|
|
429
|
+
{ silentOnly, secondaryPromptGapMs: promptGapMs }
|
|
430
|
+
)
|
|
423
431
|
|
|
424
432
|
// Silent-only: the non-prompting probe above is the whole attempt. Without
|
|
425
433
|
// an already-authorized account, stop here — every path below
|
|
@@ -438,12 +446,20 @@ export class InjectedConnector implements Connector {
|
|
|
438
446
|
availableAddresses
|
|
439
447
|
}
|
|
440
448
|
} else {
|
|
449
|
+
// A non-EVM target ran the secondary gathers above first. When one of
|
|
450
|
+
// them prompted, its window may have just closed: space the target's own
|
|
451
|
+
// prompt from it the same way. Reads of an existing authorization (and
|
|
452
|
+
// an EVM target, which skips those gathers) leave nothing to space from.
|
|
453
|
+
if (secondaryPrompted) {
|
|
454
|
+
await waitBeforeSecondaryPrompt(promptGapMs)
|
|
455
|
+
}
|
|
441
456
|
// Not connected, need to establish a new connection.
|
|
442
457
|
result = await this.connectToNamespace(
|
|
443
458
|
targetNamespace,
|
|
444
459
|
network,
|
|
445
460
|
provider,
|
|
446
461
|
requiredAddresses,
|
|
462
|
+
promptGapMs,
|
|
447
463
|
attempt
|
|
448
464
|
)
|
|
449
465
|
}
|
|
@@ -458,7 +474,11 @@ export class InjectedConnector implements Connector {
|
|
|
458
474
|
// prompt, and a missing secondary Tron address is the documented price of
|
|
459
475
|
// never prompting.
|
|
460
476
|
if (targetNamespace !== 'tron' && !silentOnly) {
|
|
461
|
-
await this.enrichWithTron(
|
|
477
|
+
await this.enrichWithTron(
|
|
478
|
+
provider,
|
|
479
|
+
result.availableAddresses,
|
|
480
|
+
promptGapMs
|
|
481
|
+
)
|
|
462
482
|
}
|
|
463
483
|
|
|
464
484
|
return result
|
|
@@ -469,19 +489,25 @@ export class InjectedConnector implements Connector {
|
|
|
469
489
|
targetNamespace: Namespace,
|
|
470
490
|
network: Network,
|
|
471
491
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
472
|
-
requiredAddresses
|
|
473
|
-
|
|
492
|
+
requiredAddresses: readonly string[] | undefined,
|
|
493
|
+
promptGapMs: number,
|
|
494
|
+
attempt: ConnectAttempt
|
|
474
495
|
): Promise<ConnectorResult> {
|
|
475
496
|
switch (targetNamespace) {
|
|
476
497
|
case 'eip155':
|
|
477
498
|
return await this.connectionManager.connectEthereum(
|
|
478
499
|
network,
|
|
479
500
|
provider,
|
|
501
|
+
promptGapMs,
|
|
480
502
|
attempt
|
|
481
503
|
)
|
|
482
504
|
|
|
483
505
|
case 'solana':
|
|
484
|
-
return await this.connectionManager.connectSolana(
|
|
506
|
+
return await this.connectionManager.connectSolana(
|
|
507
|
+
network,
|
|
508
|
+
provider,
|
|
509
|
+
promptGapMs
|
|
510
|
+
)
|
|
485
511
|
|
|
486
512
|
case 'tron':
|
|
487
513
|
if (this.tronConnector) {
|
|
@@ -491,16 +517,25 @@ export class InjectedConnector implements Connector {
|
|
|
491
517
|
this.connectionManager.setCurrentNetworkId(network.id)
|
|
492
518
|
return result
|
|
493
519
|
}
|
|
494
|
-
return await this.connectionManager.connectTron(
|
|
520
|
+
return await this.connectionManager.connectTron(
|
|
521
|
+
network,
|
|
522
|
+
provider,
|
|
523
|
+
promptGapMs
|
|
524
|
+
)
|
|
495
525
|
|
|
496
526
|
case 'tvm':
|
|
497
|
-
return await this.connectionManager.connectTon(
|
|
527
|
+
return await this.connectionManager.connectTon(
|
|
528
|
+
network,
|
|
529
|
+
provider,
|
|
530
|
+
promptGapMs
|
|
531
|
+
)
|
|
498
532
|
|
|
499
533
|
case 'bip122':
|
|
500
534
|
return await this.connectionManager.connectBitcoin(
|
|
501
535
|
network,
|
|
502
536
|
provider,
|
|
503
|
-
requiredAddresses
|
|
537
|
+
requiredAddresses,
|
|
538
|
+
promptGapMs
|
|
504
539
|
)
|
|
505
540
|
|
|
506
541
|
default:
|
|
@@ -520,9 +555,11 @@ export class InjectedConnector implements Connector {
|
|
|
520
555
|
*/
|
|
521
556
|
private async enrichWithTron(
|
|
522
557
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
523
|
-
availableAddresses: AvailableAddress[]
|
|
558
|
+
availableAddresses: AvailableAddress[],
|
|
559
|
+
promptGapMs: number
|
|
524
560
|
): Promise<void> {
|
|
525
|
-
|
|
561
|
+
const tronConnector = this.tronConnector
|
|
562
|
+
if (!tronConnector) return
|
|
526
563
|
|
|
527
564
|
// The eager Tron gather runs even when framed. The Tron connector is
|
|
528
565
|
// bridge-aware (ONC-3383, #176): when a `BridgeParent` is present it resolves
|
|
@@ -547,51 +584,59 @@ export class InjectedConnector implements Connector {
|
|
|
547
584
|
if (!tronNetwork) return
|
|
548
585
|
|
|
549
586
|
const start = Date.now()
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
//
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
step: 'secondaryGather',
|
|
563
|
-
outcome: 'timedOut',
|
|
564
|
-
durationMs: Date.now() - start,
|
|
565
|
-
namespace: 'tron',
|
|
566
|
-
timeoutMs: this.secondaryGatherTimeoutMs
|
|
567
|
-
})
|
|
568
|
-
}
|
|
569
|
-
)
|
|
570
|
-
if (!result) return
|
|
571
|
-
for (const addr of result.availableAddresses) {
|
|
572
|
-
const dup = availableAddresses.some(
|
|
573
|
-
a => a.networkId === addr.networkId && a.address === addr.address
|
|
587
|
+
// Pass the provider — the Tron connector reads its tron.injectedId.
|
|
588
|
+
// Deadline-bounded like the ConnectionManager gathers (ONC-183): this runs
|
|
589
|
+
// after the target namespace is already authorized, so a Tron prompt the
|
|
590
|
+
// user never answers must cost the Tron address, not the whole connect.
|
|
591
|
+
const run = await runSecondaryLeg(this.secondaryGatherTimeoutMs, leg =>
|
|
592
|
+
// Marked at the wallet request itself: the connector first discovers the
|
|
593
|
+
// provider, and a wallet that is not installed sends nothing. A leg whose
|
|
594
|
+
// deadline passed during that discovery sends nothing either: the throw
|
|
595
|
+
// stops the connector before its request.
|
|
596
|
+
waitBeforeSecondaryPrompt(promptGapMs, leg.signal).then(() =>
|
|
597
|
+
tronConnector.connect(tronNetwork, provider, undefined, () =>
|
|
598
|
+
markPrompted(leg)
|
|
574
599
|
)
|
|
575
|
-
|
|
576
|
-
|
|
600
|
+
)
|
|
601
|
+
)
|
|
602
|
+
const durationMs = Date.now() - start
|
|
603
|
+
if (run.status === 'timedOut') {
|
|
577
604
|
this.steps.report({
|
|
578
605
|
step: 'secondaryGather',
|
|
579
|
-
outcome: '
|
|
580
|
-
durationMs
|
|
581
|
-
namespace: 'tron'
|
|
606
|
+
outcome: 'timedOut',
|
|
607
|
+
durationMs,
|
|
608
|
+
namespace: 'tron',
|
|
609
|
+
timeoutMs: this.secondaryGatherTimeoutMs,
|
|
610
|
+
prompted: run.prompted
|
|
582
611
|
})
|
|
583
|
-
|
|
612
|
+
return
|
|
613
|
+
}
|
|
614
|
+
if (run.status === 'failed') {
|
|
584
615
|
// Tron unavailable or the user declined the prompt — continue without it,
|
|
585
616
|
// same as the Solana/Tron/TON gathers in ConnectionManager.
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
617
|
+
this.steps.report({
|
|
618
|
+
step: 'secondaryGather',
|
|
619
|
+
...gatherFailure(run.error),
|
|
620
|
+
durationMs,
|
|
621
|
+
namespace: 'tron',
|
|
622
|
+
prompted: run.prompted
|
|
623
|
+
})
|
|
624
|
+
return
|
|
625
|
+
}
|
|
626
|
+
if (!run.value) return
|
|
627
|
+
for (const addr of run.value.availableAddresses) {
|
|
628
|
+
const dup = availableAddresses.some(
|
|
629
|
+
a => a.networkId === addr.networkId && a.address === addr.address
|
|
630
|
+
)
|
|
631
|
+
if (!dup) availableAddresses.push(addr)
|
|
594
632
|
}
|
|
633
|
+
this.steps.report({
|
|
634
|
+
step: 'secondaryGather',
|
|
635
|
+
outcome: 'ok',
|
|
636
|
+
durationMs,
|
|
637
|
+
namespace: 'tron',
|
|
638
|
+
prompted: run.prompted
|
|
639
|
+
})
|
|
595
640
|
}
|
|
596
641
|
|
|
597
642
|
/**
|