@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
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type WalletStandardInfo,
|
|
11
11
|
type LegacyInjectedSolanaDiscoveryFailure
|
|
12
12
|
} from '../../wallet-standard-discovery'
|
|
13
|
+
import type { StandardWalletAdapter } from '@solana/wallet-standard-wallet-adapter-base'
|
|
13
14
|
import { StorageService } from '../storage-service'
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -103,6 +104,53 @@ export class SolanaWalletService {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The silent-only probe (see `ConnectorConnectOptions.silentOnly`): returns
|
|
109
|
+
* the already-authorized address, or null — and NEVER prompts.
|
|
110
|
+
*
|
|
111
|
+
* Passive check first (no storage-flag reconnect: that path calls the
|
|
112
|
+
* interactive `adapter.connect()`). Then, only for a Wallet Standard wallet
|
|
113
|
+
* that ALREADY exposes an account to this origin (`wallet.accounts`),
|
|
114
|
+
* `adapter.autoConnect()` to adopt it. With an account present the Standard
|
|
115
|
+
* adapter connects to it directly and never calls the wallet's
|
|
116
|
+
* `standard:connect`, so no wallet request is made at all. That gate matters:
|
|
117
|
+
* `silent: true` is only a hint the spec lets wallets ignore (Trust and
|
|
118
|
+
* MetaMask show a normal Connect popup for it), and a `standard:connect` that
|
|
119
|
+
* never settles would leave the adapter `connecting` until reload, turning the
|
|
120
|
+
* user's later tap into a no-op. The price is a miss for a wallet that trusts
|
|
121
|
+
* the origin but has not re-exposed its accounts on this page; the caller
|
|
122
|
+
* falls back to its normal connect. Never called for the legacy injected
|
|
123
|
+
* fallback, whose inherited `autoConnect()` is a plain prompting `connect()`.
|
|
124
|
+
*/
|
|
125
|
+
async checkExistingConnectionSilently(
|
|
126
|
+
adapter: SolanaAdapter,
|
|
127
|
+
walletUuid: string,
|
|
128
|
+
supportsStandardConnect: boolean
|
|
129
|
+
): Promise<string | null> {
|
|
130
|
+
const passive = await this.checkExistingConnection(adapter, walletUuid, {
|
|
131
|
+
allowSilentReconnect: false
|
|
132
|
+
})
|
|
133
|
+
if (passive || !supportsStandardConnect) {
|
|
134
|
+
return passive
|
|
135
|
+
}
|
|
136
|
+
// A bridged (framed) adapter is a Comlink proxy: `wallet`, `accounts` and
|
|
137
|
+
// `length` are all truthy proxies whatever the parent holds. Only a
|
|
138
|
+
// materialized, nonempty array proves an account, so a bridged adapter
|
|
139
|
+
// never gets the `autoConnect()` probe.
|
|
140
|
+
const exposedAccounts = (adapter as Partial<StandardWalletAdapter>).wallet
|
|
141
|
+
?.accounts
|
|
142
|
+
if (!Array.isArray(exposedAccounts) || exposedAccounts.length === 0) {
|
|
143
|
+
return null
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
await (adapter as StandardWalletAdapter).autoConnect()
|
|
147
|
+
return (await adapter.publicKey?.toBase58()) ?? null
|
|
148
|
+
} catch {
|
|
149
|
+
// The account vanished between the gate and the adopt: no address.
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
106
154
|
/**
|
|
107
155
|
* Connect to wallet
|
|
108
156
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { createWalletClient, custom } from 'viem'
|
|
2
3
|
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
3
4
|
import { parseError, extractTonSdkErrorMessage } from './error-utils'
|
|
4
5
|
|
|
@@ -75,6 +76,120 @@ describe('parseError (injected)', () => {
|
|
|
75
76
|
expect(thrownBy({ code: Infinity, message: 'x' }).code).toBeUndefined()
|
|
76
77
|
})
|
|
77
78
|
})
|
|
79
|
+
|
|
80
|
+
describe('providerReason', () => {
|
|
81
|
+
// Reproduces the real path: viem's sendTransaction over an injected provider
|
|
82
|
+
// that rejects the way Trust Wallet Android does, with a bare string.
|
|
83
|
+
const viemErrorFor = async (rejection: unknown): Promise<unknown> => {
|
|
84
|
+
const from = '0x1234567890123456789012345678901234567890'
|
|
85
|
+
const client = createWalletClient({
|
|
86
|
+
account: from,
|
|
87
|
+
transport: custom({
|
|
88
|
+
request: async () => {
|
|
89
|
+
throw rejection
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
try {
|
|
94
|
+
await client.sendTransaction({
|
|
95
|
+
account: from,
|
|
96
|
+
chain: null,
|
|
97
|
+
to: '0x0987654321098765432109876543210987654321',
|
|
98
|
+
value: 1n
|
|
99
|
+
})
|
|
100
|
+
} catch (error) {
|
|
101
|
+
return error
|
|
102
|
+
}
|
|
103
|
+
throw new Error('sendTransaction did not reject')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
it('recovers a bare-string wallet rejection that viem reduces to "unknown RPC error"', async () => {
|
|
107
|
+
const err = thrownBy(await viemErrorFor('cancelled'))
|
|
108
|
+
expect(err.message).toContain('An unknown RPC error occurred.')
|
|
109
|
+
expect(err.message).not.toContain('cancelled')
|
|
110
|
+
expect(err.providerReason).toBe('cancelled')
|
|
111
|
+
expect(err.type).toBe('unknown')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('classifies a bare-string user rejection as rejected', async () => {
|
|
115
|
+
const err = thrownBy(await viemErrorFor('User rejected the request'))
|
|
116
|
+
expect(err.message).toContain('An unknown RPC error occurred.')
|
|
117
|
+
expect(err.providerReason).toBe('User rejected the request')
|
|
118
|
+
expect(err.type).toBe('rejected')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('leaves a standard EIP-1193 rejection (4001, MetaMask) as it was', async () => {
|
|
122
|
+
const err = thrownBy(
|
|
123
|
+
await viemErrorFor({
|
|
124
|
+
code: 4001,
|
|
125
|
+
message: 'MetaMask Tx Signature: User denied transaction signature.'
|
|
126
|
+
})
|
|
127
|
+
)
|
|
128
|
+
expect(err.type).toBe('rejected')
|
|
129
|
+
expect(err.message).toContain('User denied transaction signature.')
|
|
130
|
+
expect(err.providerReason).toBeUndefined()
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('leaves an Error rejection with its own message as it was', async () => {
|
|
134
|
+
const err = thrownBy(await viemErrorFor(new Error('Request timed out')))
|
|
135
|
+
expect(err.message).toContain('Request timed out')
|
|
136
|
+
expect(err.providerReason).toBeUndefined()
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('omits the reason when viem already put it in the message', async () => {
|
|
140
|
+
const err = thrownBy(
|
|
141
|
+
await viemErrorFor({ code: -32000, message: 'insufficient funds' })
|
|
142
|
+
)
|
|
143
|
+
expect(err.message).toContain('insufficient funds')
|
|
144
|
+
expect(err.providerReason).toBeUndefined()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('omits the reason when the error has no cause', () => {
|
|
148
|
+
expect(
|
|
149
|
+
thrownBy(new Error('Something odd happened')).providerReason
|
|
150
|
+
).toBeUndefined()
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('takes the deepest message in a chain of Error causes', () => {
|
|
154
|
+
const inner = new Error('nonce too low')
|
|
155
|
+
const middle = new Error('wrapped', { cause: inner })
|
|
156
|
+
const outer = new Error('Transaction failed', { cause: middle })
|
|
157
|
+
expect(thrownBy(outer).providerReason).toBe('nonce too low')
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('ignores a blank string cause', () => {
|
|
161
|
+
expect(
|
|
162
|
+
thrownBy(new Error('Transaction failed', { cause: ' ' }))
|
|
163
|
+
.providerReason
|
|
164
|
+
).toBeUndefined()
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it('keeps a long reason whole, so an address in it is never cut short before core redacts it', () => {
|
|
168
|
+
const address = '0x1234567890123456789012345678901234567890'
|
|
169
|
+
const reason = `${'x'.repeat(180)} ${address}`
|
|
170
|
+
const err = thrownBy(new Error('Transaction failed', { cause: reason }))
|
|
171
|
+
expect(err.providerReason).toBe(reason)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('stops at a cyclic cause chain instead of looping', () => {
|
|
175
|
+
const a: { message: string; cause?: unknown } = { message: 'a' }
|
|
176
|
+
const b = { message: 'b', cause: a }
|
|
177
|
+
a.cause = b
|
|
178
|
+
expect(() => thrownBy(a)).not.toThrow()
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
it('survives a cause getter that throws', () => {
|
|
182
|
+
const hostile = { message: 'boom' }
|
|
183
|
+
Object.defineProperty(hostile, 'cause', {
|
|
184
|
+
get() {
|
|
185
|
+
throw new Error('poisoned')
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
const err = thrownBy(hostile)
|
|
189
|
+
expect(err.message).toBe('boom')
|
|
190
|
+
expect(err.providerReason).toBeUndefined()
|
|
191
|
+
})
|
|
192
|
+
})
|
|
78
193
|
})
|
|
79
194
|
|
|
80
195
|
describe('extractTonSdkErrorMessage', () => {
|
package/src/utils/error-utils.ts
CHANGED
|
@@ -26,6 +26,48 @@ export function extractTonSdkErrorMessage(error: unknown): string {
|
|
|
26
26
|
return msg
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// No length cap here: core telemetry redacts addresses before it caps, and a cap
|
|
30
|
+
// applied first could cut an address short enough to slip past the redaction.
|
|
31
|
+
const MAX_CAUSE_DEPTH = 5
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The wallet's own rejection text from the deepest `cause` in the chain.
|
|
35
|
+
*
|
|
36
|
+
* viem wraps a provider rejection twice (TransactionExecutionError →
|
|
37
|
+
* UnknownRpcError → original) and only surfaces the original in its message when
|
|
38
|
+
* it was an Error. A wallet that rejects with a bare string (Trust Wallet Android:
|
|
39
|
+
* `"cancelled"`) is reduced to "An unknown RPC error occurred.", so the reason
|
|
40
|
+
* survives only as the innermost `cause`.
|
|
41
|
+
*/
|
|
42
|
+
function extractProviderReason(
|
|
43
|
+
error: unknown,
|
|
44
|
+
message: string
|
|
45
|
+
): string | undefined {
|
|
46
|
+
try {
|
|
47
|
+
let current: unknown = error
|
|
48
|
+
let reason: string | undefined
|
|
49
|
+
for (let depth = 0; depth < MAX_CAUSE_DEPTH; depth++) {
|
|
50
|
+
if (!current || typeof current !== 'object' || !('cause' in current))
|
|
51
|
+
break
|
|
52
|
+
const cause: unknown = (current as { cause: unknown }).cause
|
|
53
|
+
if (typeof cause === 'string') {
|
|
54
|
+
reason = cause
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
if (cause && typeof cause === 'object') {
|
|
58
|
+
const causeMessage: unknown = (cause as { message?: unknown }).message
|
|
59
|
+
if (typeof causeMessage === 'string') reason = causeMessage
|
|
60
|
+
}
|
|
61
|
+
current = cause
|
|
62
|
+
}
|
|
63
|
+
const trimmed = reason?.trim()
|
|
64
|
+
if (!trimmed || message.includes(trimmed)) return undefined
|
|
65
|
+
return trimmed
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
29
71
|
/**
|
|
30
72
|
* Parse an error and throw a WalletConnectorError
|
|
31
73
|
* Detects if the error is a user rejection or an unknown error
|
|
@@ -72,7 +114,11 @@ export function parseError(error: unknown): never {
|
|
|
72
114
|
message = String(error)
|
|
73
115
|
}
|
|
74
116
|
|
|
75
|
-
|
|
117
|
+
const providerReason = extractProviderReason(error, message)
|
|
118
|
+
|
|
119
|
+
// If not already marked as rejected, check message patterns. The provider
|
|
120
|
+
// reason counts too: a wallet that rejects with a bare string loses it from
|
|
121
|
+
// viem's message.
|
|
76
122
|
if (!isRejected) {
|
|
77
123
|
const rejectionPatterns = [
|
|
78
124
|
'user rejected',
|
|
@@ -90,7 +136,7 @@ export function parseError(error: unknown): never {
|
|
|
90
136
|
'user rejects'
|
|
91
137
|
]
|
|
92
138
|
|
|
93
|
-
const lowerMessage = message
|
|
139
|
+
const lowerMessage = `${message} ${providerReason ?? ''}`.toLowerCase()
|
|
94
140
|
isRejected = rejectionPatterns.some(pattern =>
|
|
95
141
|
lowerMessage.includes(pattern.toLowerCase())
|
|
96
142
|
)
|
|
@@ -99,7 +145,8 @@ export function parseError(error: unknown): never {
|
|
|
99
145
|
const walletError: WalletError = {
|
|
100
146
|
type: isRejected ? 'rejected' : 'unknown',
|
|
101
147
|
message,
|
|
102
|
-
...(numericCode !== undefined ? { code: numericCode } : {})
|
|
148
|
+
...(numericCode !== undefined ? { code: numericCode } : {}),
|
|
149
|
+
...(providerReason ? { providerReason } : {})
|
|
103
150
|
}
|
|
104
151
|
|
|
105
152
|
throw new WalletConnectorError(walletError)
|