@meshconnect/uwc-injected-connector 0.26.3 → 0.27.1
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 +13 -3
- package/dist/injected-connector.js.map +1 -1
- package/dist/services/connection-manager.d.ts +3 -1
- package/dist/services/connection-manager.d.ts.map +1 -1
- package/dist/services/connection-manager.js +49 -21
- 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 +5 -0
- package/dist/services/ethereum/ethereum-transaction-builder.js.map +1 -1
- package/dist/services/ethereum/ethereum-transaction-service.d.ts.map +1 -1
- package/dist/services/ethereum/ethereum-transaction-service.js +1 -0
- package/dist/services/ethereum/ethereum-transaction-service.js.map +1 -1
- package/dist/services/solana/solana-wallet-service.d.ts +19 -0
- package/dist/services/solana/solana-wallet-service.d.ts.map +1 -1
- package/dist/services/solana/solana-wallet-service.js +43 -0
- package/dist/services/solana/solana-wallet-service.js.map +1 -1
- package/dist/utils/error-utils.d.ts.map +1 -1
- package/dist/utils/error-utils.js +47 -3
- package/dist/utils/error-utils.js.map +1 -1
- package/package.json +6 -6
- package/src/injected-connector.test.ts +67 -0
- package/src/injected-connector.ts +18 -3
- package/src/services/connection-manager.test.ts +446 -0
- package/src/services/connection-manager.ts +84 -48
- package/src/services/ethereum/ethereum-transaction-builder.test.ts +3 -1
- package/src/services/ethereum/ethereum-transaction-builder.ts +5 -0
- package/src/services/ethereum/ethereum-transaction-service.test.ts +206 -0
- package/src/services/ethereum/ethereum-transaction-service.ts +1 -0
- package/src/services/solana/solana-wallet-service.silent-only.test.ts +162 -0
- package/src/services/solana/solana-wallet-service.ts +48 -0
- package/src/utils/error-utils.test.ts +115 -0
- package/src/utils/error-utils.ts +50 -3
|
@@ -196,6 +196,19 @@ export interface SecondarySolanaConnectGatheredInfo {
|
|
|
196
196
|
*/
|
|
197
197
|
const MAX_INJECTED_ID_LENGTH = 64
|
|
198
198
|
|
|
199
|
+
/**
|
|
200
|
+
* Whether a detected Solana wallet implements Wallet Standard `standard:connect`,
|
|
201
|
+
* i.e. whether its adapter's `autoConnect()` is a genuinely SILENT connect
|
|
202
|
+
* (`standard:connect` with `silent: true`). The legacy injected fallback
|
|
203
|
+
* (`LegacyInjectedSolanaWalletAdapter`) advertises no `standard:connect`, and
|
|
204
|
+
* its inherited `autoConnect()` is a plain, prompting `connect()`. Read from the
|
|
205
|
+
* marshalled `features` list rather than `instanceof`, so it holds for bridged
|
|
206
|
+
* (iframe) adapters too.
|
|
207
|
+
*/
|
|
208
|
+
function supportsStandardConnect(wallet: { features?: readonly string[] }) {
|
|
209
|
+
return wallet.features?.includes('standard:connect') === true
|
|
210
|
+
}
|
|
211
|
+
|
|
199
212
|
/**
|
|
200
213
|
* Does `address` satisfy the caller's pinned allow-list?
|
|
201
214
|
*
|
|
@@ -482,7 +495,8 @@ export class ConnectionManager {
|
|
|
482
495
|
async checkExistingConnections(
|
|
483
496
|
targetNamespace: Namespace,
|
|
484
497
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
485
|
-
requiredAddresses?: readonly string[]
|
|
498
|
+
requiredAddresses?: readonly string[],
|
|
499
|
+
options?: { silentOnly?: boolean }
|
|
486
500
|
): Promise<{
|
|
487
501
|
address: string | null
|
|
488
502
|
availableAddresses: AvailableAddress[]
|
|
@@ -494,6 +508,22 @@ export class ConnectionManager {
|
|
|
494
508
|
|
|
495
509
|
const availableAddresses: AvailableAddress[] = []
|
|
496
510
|
let currentAddress: string | null = null
|
|
511
|
+
// Silent-only (see `ConnectorConnectOptions.silentOnly`): every probe here
|
|
512
|
+
// must stay non-prompting. The secondary gathers normally fall back to a
|
|
513
|
+
// PROMPTING connect, so under silent-only they run only once the target is
|
|
514
|
+
// authorized, and then without those fallbacks.
|
|
515
|
+
const silentOnly = options?.silentOnly === true
|
|
516
|
+
const gatherOthers = async (
|
|
517
|
+
connectedNamespace: 'eip155' | 'solana' | 'tron' | 'tvm' | 'bip122'
|
|
518
|
+
): Promise<void> => {
|
|
519
|
+
if (silentOnly && !currentAddress) return
|
|
520
|
+
await this.checkAndAddOtherNamespaceAddresses(
|
|
521
|
+
connectedNamespace,
|
|
522
|
+
provider,
|
|
523
|
+
availableAddresses,
|
|
524
|
+
silentOnly
|
|
525
|
+
)
|
|
526
|
+
}
|
|
497
527
|
|
|
498
528
|
if (targetNamespace === 'eip155') {
|
|
499
529
|
// Check Ethereum connection
|
|
@@ -534,11 +564,7 @@ export class ConnectionManager {
|
|
|
534
564
|
availableAddresses.push(...ethAddresses)
|
|
535
565
|
}
|
|
536
566
|
|
|
537
|
-
await
|
|
538
|
-
'eip155',
|
|
539
|
-
provider,
|
|
540
|
-
availableAddresses
|
|
541
|
-
)
|
|
567
|
+
await gatherOthers('eip155')
|
|
542
568
|
} else if (targetNamespace === 'solana') {
|
|
543
569
|
// Check Solana connection
|
|
544
570
|
const solanaAccount = this.solanaService.getAccount()
|
|
@@ -551,10 +577,16 @@ export class ConnectionManager {
|
|
|
551
577
|
if (walletUuid) {
|
|
552
578
|
const wallet = this.solanaService.findWalletByUuid(walletUuid)
|
|
553
579
|
if (wallet?.adapter) {
|
|
554
|
-
const address =
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
580
|
+
const address = silentOnly
|
|
581
|
+
? await this.solanaService.checkExistingConnectionSilently(
|
|
582
|
+
wallet.adapter,
|
|
583
|
+
walletUuid,
|
|
584
|
+
supportsStandardConnect(wallet)
|
|
585
|
+
)
|
|
586
|
+
: await this.solanaService.checkExistingConnection(
|
|
587
|
+
wallet.adapter,
|
|
588
|
+
walletUuid
|
|
589
|
+
)
|
|
558
590
|
if (address) {
|
|
559
591
|
currentAddress = address
|
|
560
592
|
this.solanaService.setConnectionState(
|
|
@@ -576,11 +608,7 @@ export class ConnectionManager {
|
|
|
576
608
|
availableAddresses.push(...solanaAddresses)
|
|
577
609
|
}
|
|
578
610
|
|
|
579
|
-
await
|
|
580
|
-
'solana',
|
|
581
|
-
provider,
|
|
582
|
-
availableAddresses
|
|
583
|
-
)
|
|
611
|
+
await gatherOthers('solana')
|
|
584
612
|
} else if (targetNamespace === 'tron') {
|
|
585
613
|
// Check Tron connection
|
|
586
614
|
const tronAccount = this.tronService.getAccount()
|
|
@@ -613,11 +641,7 @@ export class ConnectionManager {
|
|
|
613
641
|
availableAddresses.push(...tronAddresses)
|
|
614
642
|
}
|
|
615
643
|
|
|
616
|
-
await
|
|
617
|
-
'tron',
|
|
618
|
-
provider,
|
|
619
|
-
availableAddresses
|
|
620
|
-
)
|
|
644
|
+
await gatherOthers('tron')
|
|
621
645
|
} else if (targetNamespace === 'tvm') {
|
|
622
646
|
const tonAccount = this.tonService.getAccount()
|
|
623
647
|
if (tonAccount) {
|
|
@@ -638,11 +662,7 @@ export class ConnectionManager {
|
|
|
638
662
|
availableAddresses.push(...tonAddresses)
|
|
639
663
|
}
|
|
640
664
|
|
|
641
|
-
await
|
|
642
|
-
'tvm',
|
|
643
|
-
provider,
|
|
644
|
-
availableAddresses
|
|
645
|
-
)
|
|
665
|
+
await gatherOthers('tvm')
|
|
646
666
|
} else if (targetNamespace === 'bip122') {
|
|
647
667
|
// A live session only counts as "already connected" when it satisfies the
|
|
648
668
|
// caller's pinned allow-list. Otherwise fall through so the prompting
|
|
@@ -692,11 +712,7 @@ export class ConnectionManager {
|
|
|
692
712
|
availableAddresses.push(...bitcoinAddresses)
|
|
693
713
|
}
|
|
694
714
|
|
|
695
|
-
await
|
|
696
|
-
'bip122',
|
|
697
|
-
provider,
|
|
698
|
-
availableAddresses
|
|
699
|
-
)
|
|
715
|
+
await gatherOthers('bip122')
|
|
700
716
|
}
|
|
701
717
|
|
|
702
718
|
return { address: currentAddress, availableAddresses }
|
|
@@ -707,7 +723,8 @@ export class ConnectionManager {
|
|
|
707
723
|
*/
|
|
708
724
|
private async checkAndAddEthereumAddresses(
|
|
709
725
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
710
|
-
availableAddresses: AvailableAddress[]
|
|
726
|
+
availableAddresses: AvailableAddress[],
|
|
727
|
+
silentOnly = false
|
|
711
728
|
): Promise<SecondaryGatherOutcome> {
|
|
712
729
|
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
713
730
|
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
@@ -730,7 +747,7 @@ export class ConnectionManager {
|
|
|
730
747
|
const ethAddress =
|
|
731
748
|
accounts && accounts.length > 0
|
|
732
749
|
? accounts[0]
|
|
733
|
-
: skipFramedSecondaryConnect()
|
|
750
|
+
: silentOnly || skipFramedSecondaryConnect()
|
|
734
751
|
? undefined
|
|
735
752
|
: await this.ethereumService.connect(
|
|
736
753
|
ethWallet.provider,
|
|
@@ -770,7 +787,8 @@ export class ConnectionManager {
|
|
|
770
787
|
*/
|
|
771
788
|
private async checkAndAddSolanaAddresses(
|
|
772
789
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
773
|
-
availableAddresses: AvailableAddress[]
|
|
790
|
+
availableAddresses: AvailableAddress[],
|
|
791
|
+
silentOnly = false
|
|
774
792
|
): Promise<SecondaryGatherOutcome> {
|
|
775
793
|
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
776
794
|
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
@@ -793,13 +811,19 @@ export class ConnectionManager {
|
|
|
793
811
|
this.solanaService.findWalletByUuid(solanaWalletUuid)
|
|
794
812
|
if (solanaWallet?.adapter) {
|
|
795
813
|
try {
|
|
796
|
-
const existingAddress =
|
|
797
|
-
await this.solanaService.
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
814
|
+
const existingAddress = silentOnly
|
|
815
|
+
? await this.solanaService.checkExistingConnectionSilently(
|
|
816
|
+
solanaWallet.adapter,
|
|
817
|
+
solanaWalletUuid,
|
|
818
|
+
supportsStandardConnect(solanaWallet)
|
|
819
|
+
)
|
|
820
|
+
: await this.solanaService.checkExistingConnection(
|
|
821
|
+
solanaWallet.adapter,
|
|
822
|
+
solanaWalletUuid,
|
|
823
|
+
{ allowSilentReconnect: !skipLegacyConnect }
|
|
824
|
+
)
|
|
802
825
|
const canConnect =
|
|
826
|
+
!silentOnly &&
|
|
803
827
|
!skipLegacyConnect &&
|
|
804
828
|
!skipFramedSecondaryConnect(/* namespaceSafeFramed */ true)
|
|
805
829
|
const solanaAddress =
|
|
@@ -866,7 +890,8 @@ export class ConnectionManager {
|
|
|
866
890
|
*/
|
|
867
891
|
private async checkAndAddTronAddresses(
|
|
868
892
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
869
|
-
availableAddresses: AvailableAddress[]
|
|
893
|
+
availableAddresses: AvailableAddress[],
|
|
894
|
+
silentOnly = false
|
|
870
895
|
): Promise<SecondaryGatherOutcome> {
|
|
871
896
|
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
872
897
|
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
@@ -885,7 +910,8 @@ export class ConnectionManager {
|
|
|
885
910
|
(await this.tronService.checkExistingConnection(
|
|
886
911
|
tronWallet.provider
|
|
887
912
|
)) ||
|
|
888
|
-
(
|
|
913
|
+
(silentOnly ||
|
|
914
|
+
skipFramedSecondaryConnect(/* namespaceSafeFramed */ true)
|
|
889
915
|
? undefined
|
|
890
916
|
: await this.tronService.connect(tronWallet.provider))
|
|
891
917
|
if (address) {
|
|
@@ -919,7 +945,8 @@ export class ConnectionManager {
|
|
|
919
945
|
*/
|
|
920
946
|
private async checkAndAddTonAddresses(
|
|
921
947
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
922
|
-
availableAddresses: AvailableAddress[]
|
|
948
|
+
availableAddresses: AvailableAddress[],
|
|
949
|
+
silentOnly = false
|
|
923
950
|
): Promise<SecondaryGatherOutcome> {
|
|
924
951
|
// Default 'ok'; the internal catch below flips it so a swallowed wallet
|
|
925
952
|
// error is still REPORTED as a failure (see SecondaryGatherOutcome).
|
|
@@ -933,7 +960,7 @@ export class ConnectionManager {
|
|
|
933
960
|
if (!tonAccount) {
|
|
934
961
|
const jsBridgeKey =
|
|
935
962
|
provider.namespaceMetaData?.tvm?.detectedWallet?.jsBridgeKey
|
|
936
|
-
if (jsBridgeKey && !skipFramedSecondaryConnect()) {
|
|
963
|
+
if (jsBridgeKey && !silentOnly && !skipFramedSecondaryConnect()) {
|
|
937
964
|
try {
|
|
938
965
|
const result = await this.tonService.connect(jsBridgeKey)
|
|
939
966
|
tonAccount = result.address
|
|
@@ -1010,26 +1037,35 @@ export class ConnectionManager {
|
|
|
1010
1037
|
private async checkAndAddOtherNamespaceAddresses(
|
|
1011
1038
|
connectedNamespace: 'eip155' | 'solana' | 'tron' | 'tvm' | 'bip122',
|
|
1012
1039
|
provider: ExtensionInjectedProvider | IntegratedBrowserInjectedProvider,
|
|
1013
|
-
availableAddresses: AvailableAddress[]
|
|
1040
|
+
availableAddresses: AvailableAddress[],
|
|
1041
|
+
silentOnly = false
|
|
1014
1042
|
): Promise<void> {
|
|
1015
1043
|
if (connectedNamespace !== 'eip155') {
|
|
1016
1044
|
await this.gatherNamespace('eip155', () =>
|
|
1017
|
-
this.checkAndAddEthereumAddresses(
|
|
1045
|
+
this.checkAndAddEthereumAddresses(
|
|
1046
|
+
provider,
|
|
1047
|
+
availableAddresses,
|
|
1048
|
+
silentOnly
|
|
1049
|
+
)
|
|
1018
1050
|
)
|
|
1019
1051
|
}
|
|
1020
1052
|
if (connectedNamespace !== 'solana') {
|
|
1021
1053
|
await this.gatherNamespace('solana', () =>
|
|
1022
|
-
this.checkAndAddSolanaAddresses(
|
|
1054
|
+
this.checkAndAddSolanaAddresses(
|
|
1055
|
+
provider,
|
|
1056
|
+
availableAddresses,
|
|
1057
|
+
silentOnly
|
|
1058
|
+
)
|
|
1023
1059
|
)
|
|
1024
1060
|
}
|
|
1025
1061
|
if (connectedNamespace !== 'tron') {
|
|
1026
1062
|
await this.gatherNamespace('tron', () =>
|
|
1027
|
-
this.checkAndAddTronAddresses(provider, availableAddresses)
|
|
1063
|
+
this.checkAndAddTronAddresses(provider, availableAddresses, silentOnly)
|
|
1028
1064
|
)
|
|
1029
1065
|
}
|
|
1030
1066
|
if (connectedNamespace !== 'tvm') {
|
|
1031
1067
|
await this.gatherNamespace('tvm', () =>
|
|
1032
|
-
this.checkAndAddTonAddresses(provider, availableAddresses)
|
|
1068
|
+
this.checkAndAddTonAddresses(provider, availableAddresses, silentOnly)
|
|
1033
1069
|
)
|
|
1034
1070
|
}
|
|
1035
1071
|
if (connectedNamespace !== 'bip122') {
|
|
@@ -31,6 +31,7 @@ describe('EthereumTransactionBuilder', () => {
|
|
|
31
31
|
expect(result).toEqual({
|
|
32
32
|
to: request.to,
|
|
33
33
|
value: request.amount,
|
|
34
|
+
data: '0x',
|
|
34
35
|
gasLimit: BigInt(21000),
|
|
35
36
|
maxFeePerGas: BigInt(50000000000),
|
|
36
37
|
maxPriorityFeePerGas: BigInt(2000000000)
|
|
@@ -48,7 +49,8 @@ describe('EthereumTransactionBuilder', () => {
|
|
|
48
49
|
|
|
49
50
|
expect(result).toEqual({
|
|
50
51
|
to: request.to,
|
|
51
|
-
value: request.amount
|
|
52
|
+
value: request.amount,
|
|
53
|
+
data: '0x'
|
|
52
54
|
})
|
|
53
55
|
})
|
|
54
56
|
})
|
|
@@ -39,9 +39,14 @@ export class EthereumTransactionBuilder {
|
|
|
39
39
|
request: EVMNativeTransferRequest
|
|
40
40
|
): Promise<EVMTransactionParams> {
|
|
41
41
|
try {
|
|
42
|
+
// Explicit empty calldata: Trust Wallet's Android in-app browser rejects an
|
|
43
|
+
// eth_sendTransaction with no `data` field ("Transaction error", rejected
|
|
44
|
+
// with the bare string "cancelled"), and accepts the same request with
|
|
45
|
+
// `data: '0x'`. Empty calldata is what every node assumes when it is absent.
|
|
42
46
|
return {
|
|
43
47
|
to: request.to,
|
|
44
48
|
value: request.amount,
|
|
49
|
+
data: '0x',
|
|
45
50
|
...this.formatGasConfig(request.gasConfig)
|
|
46
51
|
}
|
|
47
52
|
} catch (error) {
|
|
@@ -114,6 +114,179 @@ describe('EthereumTransactionService', () => {
|
|
|
114
114
|
|
|
115
115
|
expect(result).toBe('0xtxhash')
|
|
116
116
|
})
|
|
117
|
+
|
|
118
|
+
// Trust Wallet's Android in-app browser fails a send without `data`.
|
|
119
|
+
it('always sends explicit empty calldata to the wallet', async () => {
|
|
120
|
+
const request: EVMNativeTransferRequest = {
|
|
121
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
122
|
+
to: '0x0987654321098765432109876543210987654321',
|
|
123
|
+
amount: 1_000_000_000_000n,
|
|
124
|
+
gasConfig: {
|
|
125
|
+
gasLimit: 21220,
|
|
126
|
+
maxFeePerGas: 25_000_000,
|
|
127
|
+
maxPriorityFeePerGas: 20_000_000
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
await service.sendTransaction(request, mockProvider)
|
|
132
|
+
|
|
133
|
+
expect(vi.mocked(mockProvider.request).mock.calls[0]?.[0]).toEqual({
|
|
134
|
+
method: 'eth_sendTransaction',
|
|
135
|
+
params: [
|
|
136
|
+
{
|
|
137
|
+
from: request.from,
|
|
138
|
+
to: request.to,
|
|
139
|
+
value: '0xe8d4a51000',
|
|
140
|
+
data: '0x',
|
|
141
|
+
gas: '0x52e4',
|
|
142
|
+
maxFeePerGas: '0x17d7840',
|
|
143
|
+
maxPriorityFeePerGas: '0x1312d00'
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('sends explicit empty calldata without a gas config', async () => {
|
|
150
|
+
const request: EVMNativeTransferRequest = {
|
|
151
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
152
|
+
to: '0x0987654321098765432109876543210987654321',
|
|
153
|
+
amount: 1n
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
await service.sendTransaction(request, mockProvider)
|
|
157
|
+
|
|
158
|
+
expect(vi.mocked(mockProvider.request).mock.calls[0]?.[0]).toEqual({
|
|
159
|
+
method: 'eth_sendTransaction',
|
|
160
|
+
params: [
|
|
161
|
+
{
|
|
162
|
+
from: request.from,
|
|
163
|
+
to: request.to,
|
|
164
|
+
value: '0x1',
|
|
165
|
+
data: '0x'
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
// Mirrors Trust Wallet's Android in-app browser, device-probed: a send without
|
|
173
|
+
// `data` fails after the user approves and rejects with the bare string
|
|
174
|
+
// "cancelled"; the same send with `data` goes through.
|
|
175
|
+
describe('wallet that requires a data field (Trust Wallet Android)', () => {
|
|
176
|
+
const FROM = '0x1234567890123456789012345678901234567890'
|
|
177
|
+
const TO = '0x0987654321098765432109876543210987654321'
|
|
178
|
+
|
|
179
|
+
const requiresData = () =>
|
|
180
|
+
({
|
|
181
|
+
request: vi.fn(
|
|
182
|
+
async ({ params }: { method: string; params: unknown[] }) => {
|
|
183
|
+
const tx = params[0] as { data?: string }
|
|
184
|
+
if (tx.data === undefined) throw 'cancelled'
|
|
185
|
+
return '0xtxhash'
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
}) as unknown as EthereumProvider
|
|
189
|
+
|
|
190
|
+
it('completes a native transfer', async () => {
|
|
191
|
+
const result = await service.sendTransaction(
|
|
192
|
+
{ from: FROM, to: TO, amount: 1_000_000_000_000n },
|
|
193
|
+
requiresData()
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
expect(result).toBe('0xtxhash')
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it('completes a zero-value native transfer', async () => {
|
|
200
|
+
const provider = requiresData()
|
|
201
|
+
|
|
202
|
+
await service.sendTransaction(
|
|
203
|
+
{ from: FROM, to: TO, amount: 0n },
|
|
204
|
+
provider
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
expect(vi.mocked(provider.request).mock.calls[0]?.[0]).toEqual({
|
|
208
|
+
method: 'eth_sendTransaction',
|
|
209
|
+
params: [{ from: FROM, to: TO, value: '0x0', data: '0x' }]
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it("reports the wallet's own reason when it still fails", async () => {
|
|
214
|
+
const provider = {
|
|
215
|
+
request: vi.fn().mockRejectedValue('cancelled')
|
|
216
|
+
} as unknown as EthereumProvider
|
|
217
|
+
|
|
218
|
+
const error = await service
|
|
219
|
+
.sendTransaction({ from: FROM, to: TO, amount: 1n }, provider)
|
|
220
|
+
.catch((e: unknown) => e)
|
|
221
|
+
|
|
222
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
223
|
+
expect(error).toMatchObject({
|
|
224
|
+
type: 'unknown',
|
|
225
|
+
providerReason: 'cancelled'
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
// The empty calldata is only for native sends: every other path keeps the
|
|
231
|
+
// exact request it sent before.
|
|
232
|
+
describe('other EVM paths keep their request', () => {
|
|
233
|
+
const FROM = '0x1234567890123456789012345678901234567890'
|
|
234
|
+
const TOKEN = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
|
|
235
|
+
const TO = '0x0987654321098765432109876543210987654321'
|
|
236
|
+
|
|
237
|
+
it('an ERC-20 transfer sends the encoded call, not empty calldata', async () => {
|
|
238
|
+
const request: EVMContractCallRequest = {
|
|
239
|
+
from: FROM,
|
|
240
|
+
contractAddress: TOKEN,
|
|
241
|
+
abi: [
|
|
242
|
+
{
|
|
243
|
+
name: 'transfer',
|
|
244
|
+
type: 'function',
|
|
245
|
+
inputs: [
|
|
246
|
+
{ name: 'to', type: 'address' },
|
|
247
|
+
{ name: 'amount', type: 'uint256' }
|
|
248
|
+
],
|
|
249
|
+
outputs: [{ name: '', type: 'bool' }],
|
|
250
|
+
stateMutability: 'nonpayable'
|
|
251
|
+
}
|
|
252
|
+
],
|
|
253
|
+
functionName: 'transfer',
|
|
254
|
+
args: [TO, 1_000_000n]
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
await service.sendTransaction(request, mockProvider)
|
|
258
|
+
|
|
259
|
+
expect(vi.mocked(mockProvider.request).mock.calls[0]?.[0]).toEqual({
|
|
260
|
+
method: 'eth_sendTransaction',
|
|
261
|
+
params: [
|
|
262
|
+
{
|
|
263
|
+
from: FROM,
|
|
264
|
+
to: TOKEN,
|
|
265
|
+
value: '0x0',
|
|
266
|
+
data:
|
|
267
|
+
'0xa9059cbb' +
|
|
268
|
+
TO.slice(2).toLowerCase().padStart(64, '0') +
|
|
269
|
+
(1_000_000).toString(16).padStart(64, '0')
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
it('a raw data transfer sends its data unchanged', async () => {
|
|
276
|
+
const request: EVMDataTransferRequest = {
|
|
277
|
+
from: FROM,
|
|
278
|
+
to: TO,
|
|
279
|
+
data: '0xdeadbeef',
|
|
280
|
+
chainId: '8453'
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
await service.sendTransaction(request, mockProvider)
|
|
284
|
+
|
|
285
|
+
expect(vi.mocked(mockProvider.request).mock.calls[0]?.[0]).toEqual({
|
|
286
|
+
method: 'eth_sendTransaction',
|
|
287
|
+
params: [{ from: FROM, to: TO, value: '0x0', data: '0xdeadbeef' }]
|
|
288
|
+
})
|
|
289
|
+
})
|
|
117
290
|
})
|
|
118
291
|
|
|
119
292
|
describe('sendContractCall', () => {
|
|
@@ -361,6 +534,39 @@ describe('EthereumTransactionService', () => {
|
|
|
361
534
|
vi.useRealTimers()
|
|
362
535
|
})
|
|
363
536
|
|
|
537
|
+
it('sends a native call in a batch without data, as before', async () => {
|
|
538
|
+
const provider = batchProvider([confirmedWithReceipts])
|
|
539
|
+
const from = '0x1234567890123456789012345678901234567890'
|
|
540
|
+
const to = '0x0987654321098765432109876543210987654321'
|
|
541
|
+
const mixed: EVMBatchTransactionRequest = {
|
|
542
|
+
...batchRequest,
|
|
543
|
+
calls: [
|
|
544
|
+
{ from, to, amount: 5n },
|
|
545
|
+
{ from, to, data: '0xa9059cbb', chainId: '42161' }
|
|
546
|
+
]
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const outcome = service.sendTransaction(mixed, provider)
|
|
550
|
+
await vi.runAllTimersAsync()
|
|
551
|
+
await outcome
|
|
552
|
+
|
|
553
|
+
expect(provider.request.mock.calls[0]?.[0]).toEqual({
|
|
554
|
+
method: 'wallet_sendCalls',
|
|
555
|
+
params: [
|
|
556
|
+
{
|
|
557
|
+
version: '2.0.0',
|
|
558
|
+
from,
|
|
559
|
+
chainId: '0xa4b1',
|
|
560
|
+
atomicRequired: true,
|
|
561
|
+
calls: [
|
|
562
|
+
{ to, value: '0x5' },
|
|
563
|
+
{ to, data: '0xa9059cbb', value: '0x0' }
|
|
564
|
+
]
|
|
565
|
+
}
|
|
566
|
+
]
|
|
567
|
+
})
|
|
568
|
+
})
|
|
569
|
+
|
|
364
570
|
it('returns the first receipt hash when the confirmation carries receipts', async () => {
|
|
365
571
|
const provider = batchProvider([confirmedWithReceipts])
|
|
366
572
|
|
|
@@ -86,6 +86,7 @@ export class EthereumTransactionService {
|
|
|
86
86
|
chain: null,
|
|
87
87
|
to: tx.to as `0x${string}`,
|
|
88
88
|
value: tx.value,
|
|
89
|
+
data: tx.data as `0x${string}`,
|
|
89
90
|
...(tx.gasLimit && { gas: tx.gasLimit }),
|
|
90
91
|
...(tx.maxFeePerGas && { maxFeePerGas: tx.maxFeePerGas }),
|
|
91
92
|
...(tx.maxPriorityFeePerGas && {
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { SolanaWalletService } from './solana-wallet-service'
|
|
3
|
+
import { StorageService } from '../storage-service'
|
|
4
|
+
import type { SolanaAdapter } from '../../wallet-standard-discovery'
|
|
5
|
+
|
|
6
|
+
// ONC-1975: the silent-only probe must return an already-authorized address or
|
|
7
|
+
// null, and must NEVER reach the interactive `adapter.connect()` or make a wallet
|
|
8
|
+
// request. A Wallet Standard wallet that already exposes an account to this
|
|
9
|
+
// origin is adopted through `autoConnect()`, which then connects to that account
|
|
10
|
+
// without calling the wallet's `standard:connect`. Without an exposed account
|
|
11
|
+
// nothing is called: some wallets ignore `silent: true` and show a popup, and a
|
|
12
|
+
// `standard:connect` that never settles would wedge the adapter. The legacy
|
|
13
|
+
// injected fallback never gets `autoConnect()`, a plain prompting connect there.
|
|
14
|
+
describe('SolanaWalletService.checkExistingConnectionSilently', () => {
|
|
15
|
+
function setup({
|
|
16
|
+
exposedAccounts,
|
|
17
|
+
withWallet = true
|
|
18
|
+
}: {
|
|
19
|
+
exposedAccounts: number
|
|
20
|
+
withWallet?: boolean
|
|
21
|
+
}) {
|
|
22
|
+
const storage = new StorageService()
|
|
23
|
+
// Even a "previously connected" flag must not trigger the storage-flag
|
|
24
|
+
// reconnect, which calls the interactive `adapter.connect()`.
|
|
25
|
+
vi.spyOn(storage, 'wasSolanaWalletPreviouslyConnected').mockReturnValue(
|
|
26
|
+
true
|
|
27
|
+
)
|
|
28
|
+
const service = new SolanaWalletService(storage)
|
|
29
|
+
const connect = vi.fn().mockImplementation(async () => {
|
|
30
|
+
adapter.publicKey = { toBase58: () => 'SolPrompted' }
|
|
31
|
+
})
|
|
32
|
+
// Mirrors StandardWalletAdapter: with an exposed account it adopts it
|
|
33
|
+
// directly; without one it would call the wallet's `standard:connect`.
|
|
34
|
+
const standardConnect = vi.fn()
|
|
35
|
+
const autoConnect = vi.fn().mockImplementation(async () => {
|
|
36
|
+
if (!adapter.wallet?.accounts.length) {
|
|
37
|
+
await standardConnect({ silent: true })
|
|
38
|
+
throw new Error('not authorized')
|
|
39
|
+
}
|
|
40
|
+
adapter.publicKey = { toBase58: () => 'SolSilent' }
|
|
41
|
+
})
|
|
42
|
+
const adapter = {
|
|
43
|
+
publicKey: undefined as { toBase58(): string } | undefined,
|
|
44
|
+
connecting: false,
|
|
45
|
+
connect,
|
|
46
|
+
autoConnect,
|
|
47
|
+
wallet: withWallet
|
|
48
|
+
? {
|
|
49
|
+
accounts: Array.from({ length: exposedAccounts }, (_, i) => ({
|
|
50
|
+
address: `Sol${i}`
|
|
51
|
+
}))
|
|
52
|
+
}
|
|
53
|
+
: undefined
|
|
54
|
+
}
|
|
55
|
+
return { service, adapter, connect, autoConnect, standardConnect }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
it('returns an already-present publicKey without any connect', async () => {
|
|
59
|
+
const { service, adapter, connect, autoConnect } = setup({
|
|
60
|
+
exposedAccounts: 1
|
|
61
|
+
})
|
|
62
|
+
adapter.publicKey = { toBase58: () => 'SolLive' }
|
|
63
|
+
|
|
64
|
+
const address = await service.checkExistingConnectionSilently(
|
|
65
|
+
adapter as unknown as SolanaAdapter,
|
|
66
|
+
'wallet-1',
|
|
67
|
+
true
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
expect(address).toBe('SolLive')
|
|
71
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
72
|
+
expect(connect).not.toHaveBeenCalled()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('adopts an account the wallet already exposes, with no wallet request', async () => {
|
|
76
|
+
const { service, adapter, connect, autoConnect, standardConnect } = setup({
|
|
77
|
+
exposedAccounts: 1
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const address = await service.checkExistingConnectionSilently(
|
|
81
|
+
adapter as unknown as SolanaAdapter,
|
|
82
|
+
'wallet-1',
|
|
83
|
+
true
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
expect(address).toBe('SolSilent')
|
|
87
|
+
expect(autoConnect).toHaveBeenCalledTimes(1)
|
|
88
|
+
expect(standardConnect).not.toHaveBeenCalled()
|
|
89
|
+
expect(connect).not.toHaveBeenCalled()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('returns null without touching the wallet when it exposes no account', async () => {
|
|
93
|
+
const { service, adapter, connect, autoConnect, standardConnect } = setup({
|
|
94
|
+
exposedAccounts: 0
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const address = await service.checkExistingConnectionSilently(
|
|
98
|
+
adapter as unknown as SolanaAdapter,
|
|
99
|
+
'wallet-1',
|
|
100
|
+
true
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
expect(address).toBeNull()
|
|
104
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
105
|
+
expect(standardConnect).not.toHaveBeenCalled()
|
|
106
|
+
expect(connect).not.toHaveBeenCalled()
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('returns null for an adapter that carries no wallet (bridged)', async () => {
|
|
110
|
+
const { service, adapter, connect, autoConnect } = setup({
|
|
111
|
+
exposedAccounts: 0,
|
|
112
|
+
withWallet: false
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const address = await service.checkExistingConnectionSilently(
|
|
116
|
+
adapter as unknown as SolanaAdapter,
|
|
117
|
+
'wallet-1',
|
|
118
|
+
true
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
expect(address).toBeNull()
|
|
122
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
123
|
+
expect(connect).not.toHaveBeenCalled()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('does not trust a proxy-shaped wallet.accounts (iframe bridge)', async () => {
|
|
127
|
+
const { service, adapter, connect, autoConnect, standardConnect } = setup({
|
|
128
|
+
exposedAccounts: 0
|
|
129
|
+
})
|
|
130
|
+
// Comlink proxies are function-backed Proxies: every property read, such
|
|
131
|
+
// as `.length`, yields another truthy proxy whatever the parent holds.
|
|
132
|
+
const proxy = (): unknown => new Proxy(() => {}, { get: () => proxy() })
|
|
133
|
+
;(adapter as { wallet: unknown }).wallet = proxy()
|
|
134
|
+
|
|
135
|
+
const address = await service.checkExistingConnectionSilently(
|
|
136
|
+
adapter as unknown as SolanaAdapter,
|
|
137
|
+
'wallet-1',
|
|
138
|
+
true
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
expect(address).toBeNull()
|
|
142
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
143
|
+
expect(standardConnect).not.toHaveBeenCalled()
|
|
144
|
+
expect(connect).not.toHaveBeenCalled()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('never calls autoConnect for a wallet without standard:connect (legacy fallback)', async () => {
|
|
148
|
+
const { service, adapter, connect, autoConnect } = setup({
|
|
149
|
+
exposedAccounts: 1
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const address = await service.checkExistingConnectionSilently(
|
|
153
|
+
adapter as unknown as SolanaAdapter,
|
|
154
|
+
'wallet-1',
|
|
155
|
+
false
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
expect(address).toBeNull()
|
|
159
|
+
expect(autoConnect).not.toHaveBeenCalled()
|
|
160
|
+
expect(connect).not.toHaveBeenCalled()
|
|
161
|
+
})
|
|
162
|
+
})
|