@meshconnect/uwc-injected-connector 0.24.4 → 0.24.7
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature-service.d.ts","sourceRoot":"","sources":["../../src/services/signature-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"signature-service.d.ts","sourceRoot":"","sources":["../../src/services/signature-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAIrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAgB7D;;GAEG;AACH,qBAAa,gBAAgB;IAC3B;;;OAGG;IACG,qBAAqB,CACzB,SAAS,EAAE,eAAe,EAC1B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,CAAC,CAsBjB;IAED;;OAEG;IACG,mBAAmB,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,CAAC,CA0BjB;IAED;;OAEG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,CAAC,CAqBjB;IAED;;OAEG;IACG,eAAe,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,CAAC,CAejB;CACF"}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import bs58 from 'bs58';
|
|
2
|
+
import { stringToHex } from 'viem';
|
|
2
3
|
import { parseError } from '../utils/error-utils';
|
|
3
4
|
import { withEIP712Domain } from '@meshconnect/uwc-types';
|
|
5
|
+
/**
|
|
6
|
+
* `personal_sign` data must be 0x-prefixed even-length hex. MetaMask accepts
|
|
7
|
+
* UTF-8 as a courtesy; Coinbase Wallet (especially the in-app browser) rejects
|
|
8
|
+
* it with EIP-1193 `-32603` "Invalid message". Pass through already-valid hex
|
|
9
|
+
* so a caller that pre-encoded is not double-encoded. Odd-length `0x…` strings
|
|
10
|
+
* are not valid hex bytes, so they are treated as UTF-8.
|
|
11
|
+
*/
|
|
12
|
+
function toPersonalSignData(message) {
|
|
13
|
+
return /^0x(?:[0-9a-fA-F]{2})*$/.test(message)
|
|
14
|
+
? message
|
|
15
|
+
: stringToHex(message);
|
|
16
|
+
}
|
|
4
17
|
/**
|
|
5
18
|
* Service for handling message signing operations for injected wallets
|
|
6
19
|
*/
|
|
@@ -44,10 +57,12 @@ export class SignatureService {
|
|
|
44
57
|
throw new Error('Address is required for signing');
|
|
45
58
|
}
|
|
46
59
|
try {
|
|
47
|
-
// Use personal_sign for Ethereum
|
|
60
|
+
// Use personal_sign for Ethereum. Hex-encode UTF-8 so Coinbase Wallet
|
|
61
|
+
// (and other strict EIP-1193 providers) accept the payload; MetaMask
|
|
62
|
+
// hex-decodes before hashing, so the EIP-191 digest is unchanged.
|
|
48
63
|
const signature = await provider.request({
|
|
49
64
|
method: 'personal_sign',
|
|
50
|
-
params: [message, address]
|
|
65
|
+
params: [toPersonalSignData(message), address]
|
|
51
66
|
});
|
|
52
67
|
return signature;
|
|
53
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature-service.js","sourceRoot":"","sources":["../../src/services/signature-service.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGjD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,KAAK,CAAC,eAAe,CACnB,OAAe,EACf,QAAsB;QAEtB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACpD,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAClE,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;YACnE,OAAO,SAAS,CAAA;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-injected-connector",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.7",
|
|
4
4
|
"description": "Injected connector for Universal Wallet Connector",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@wallet-standard/base": "^1.1.1",
|
|
26
26
|
"bs58": "6.0.0",
|
|
27
27
|
"buffer": "^6.0.3",
|
|
28
|
-
"uuid": "^14.0.
|
|
29
|
-
"viem": "^2.
|
|
28
|
+
"uuid": "^14.0.2",
|
|
29
|
+
"viem": "^2.56.3",
|
|
30
30
|
"@meshconnect/uwc-bridge-child": "0.6.0",
|
|
31
31
|
"@meshconnect/uwc-constants": "0.7.10",
|
|
32
32
|
"@meshconnect/uwc-ton-connector": "0.9.4",
|
|
@@ -157,4 +157,97 @@ describe('SignatureService (injected-connector)', () => {
|
|
|
157
157
|
).rejects.toThrow('Address is required')
|
|
158
158
|
})
|
|
159
159
|
})
|
|
160
|
+
|
|
161
|
+
describe('signEthereumMessage', () => {
|
|
162
|
+
it('hex-encodes a UTF-8 message for personal_sign', async () => {
|
|
163
|
+
const provider = makeProvider()
|
|
164
|
+
await service.signEthereumMessage('Hello', ADDRESS, provider)
|
|
165
|
+
|
|
166
|
+
expect(provider.request).toHaveBeenCalledWith({
|
|
167
|
+
method: 'personal_sign',
|
|
168
|
+
params: ['0x48656c6c6f', ADDRESS]
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('hex-encodes a SIWE-style message containing newlines and unicode', async () => {
|
|
173
|
+
const provider = makeProvider()
|
|
174
|
+
const message =
|
|
175
|
+
'link.meshconnect.com wants you to sign in with your Ethereum account:\n0xUserAddress\n\nVerify ✨'
|
|
176
|
+
const expectedHex =
|
|
177
|
+
'0x' +
|
|
178
|
+
Array.from(new TextEncoder().encode(message), b =>
|
|
179
|
+
b.toString(16).padStart(2, '0')
|
|
180
|
+
).join('')
|
|
181
|
+
|
|
182
|
+
await service.signEthereumMessage(message, ADDRESS, provider)
|
|
183
|
+
|
|
184
|
+
expect(provider.request).toHaveBeenCalledWith({
|
|
185
|
+
method: 'personal_sign',
|
|
186
|
+
params: [expectedHex, ADDRESS]
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('passes through a message that is already even-length 0x-hex', async () => {
|
|
191
|
+
const provider = makeProvider()
|
|
192
|
+
const alreadyHex = '0xdeadbeef'
|
|
193
|
+
|
|
194
|
+
await service.signEthereumMessage(alreadyHex, ADDRESS, provider)
|
|
195
|
+
|
|
196
|
+
expect(provider.request).toHaveBeenCalledWith({
|
|
197
|
+
method: 'personal_sign',
|
|
198
|
+
params: [alreadyHex, ADDRESS]
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it('utf8-encodes an odd-length 0x string instead of treating it as hex bytes', async () => {
|
|
203
|
+
const provider = makeProvider()
|
|
204
|
+
const oddHex = '0xabc'
|
|
205
|
+
const expectedHex =
|
|
206
|
+
'0x' +
|
|
207
|
+
Array.from(new TextEncoder().encode(oddHex), b =>
|
|
208
|
+
b.toString(16).padStart(2, '0')
|
|
209
|
+
).join('')
|
|
210
|
+
|
|
211
|
+
await service.signEthereumMessage(oddHex, ADDRESS, provider)
|
|
212
|
+
|
|
213
|
+
expect(provider.request).toHaveBeenCalledWith({
|
|
214
|
+
method: 'personal_sign',
|
|
215
|
+
params: [expectedHex, ADDRESS]
|
|
216
|
+
})
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('returns the signature from the provider', async () => {
|
|
220
|
+
const provider = makeProvider('0xexpectedsig')
|
|
221
|
+
const result = await service.signEthereumMessage(
|
|
222
|
+
'Hello',
|
|
223
|
+
ADDRESS,
|
|
224
|
+
provider
|
|
225
|
+
)
|
|
226
|
+
expect(result).toBe('0xexpectedsig')
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it('throws when provider is missing', async () => {
|
|
230
|
+
await expect(
|
|
231
|
+
service.signEthereumMessage(
|
|
232
|
+
'Hello',
|
|
233
|
+
ADDRESS,
|
|
234
|
+
undefined as unknown as EthereumProvider
|
|
235
|
+
)
|
|
236
|
+
).rejects.toThrow('Provider is required')
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
it('throws when message is missing', async () => {
|
|
240
|
+
const provider = makeProvider()
|
|
241
|
+
await expect(
|
|
242
|
+
service.signEthereumMessage('', ADDRESS, provider)
|
|
243
|
+
).rejects.toThrow('Message is required')
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it('throws when address is missing', async () => {
|
|
247
|
+
const provider = makeProvider()
|
|
248
|
+
await expect(
|
|
249
|
+
service.signEthereumMessage('Hello', '', provider)
|
|
250
|
+
).rejects.toThrow('Address is required')
|
|
251
|
+
})
|
|
252
|
+
})
|
|
160
253
|
})
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import type { EthereumProvider } from '../eip6963-discovery'
|
|
2
2
|
import type { TronProvider } from '../tron-discovery'
|
|
3
3
|
import bs58 from 'bs58'
|
|
4
|
+
import { stringToHex } from 'viem'
|
|
4
5
|
import { parseError } from '../utils/error-utils'
|
|
5
6
|
import type { SolanaAdapter } from '../wallet-standard-discovery'
|
|
6
7
|
import type { EIP712TypedData } from '@meshconnect/uwc-types'
|
|
7
8
|
import { withEIP712Domain } from '@meshconnect/uwc-types'
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* `personal_sign` data must be 0x-prefixed even-length hex. MetaMask accepts
|
|
12
|
+
* UTF-8 as a courtesy; Coinbase Wallet (especially the in-app browser) rejects
|
|
13
|
+
* it with EIP-1193 `-32603` "Invalid message". Pass through already-valid hex
|
|
14
|
+
* so a caller that pre-encoded is not double-encoded. Odd-length `0x…` strings
|
|
15
|
+
* are not valid hex bytes, so they are treated as UTF-8.
|
|
16
|
+
*/
|
|
17
|
+
function toPersonalSignData(message: string): string {
|
|
18
|
+
return /^0x(?:[0-9a-fA-F]{2})*$/.test(message)
|
|
19
|
+
? message
|
|
20
|
+
: stringToHex(message)
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
/**
|
|
10
24
|
* Service for handling message signing operations for injected wallets
|
|
11
25
|
*/
|
|
@@ -63,10 +77,12 @@ export class SignatureService {
|
|
|
63
77
|
}
|
|
64
78
|
|
|
65
79
|
try {
|
|
66
|
-
// Use personal_sign for Ethereum
|
|
80
|
+
// Use personal_sign for Ethereum. Hex-encode UTF-8 so Coinbase Wallet
|
|
81
|
+
// (and other strict EIP-1193 providers) accept the payload; MetaMask
|
|
82
|
+
// hex-decodes before hashing, so the EIP-191 digest is unchanged.
|
|
67
83
|
const signature = await provider.request({
|
|
68
84
|
method: 'personal_sign',
|
|
69
|
-
params: [message, address]
|
|
85
|
+
params: [toPersonalSignData(message), address]
|
|
70
86
|
})
|
|
71
87
|
|
|
72
88
|
return signature
|