@multiplatform.one/web3 8.1.0 → 8.2.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/cjs/bundler/metaMaskConnectTimeouts.cjs +6 -0
- package/dist/cjs/bundler/metaMaskConnectTimeouts.native.js +6 -0
- package/dist/cjs/bundler/metaMaskConnectTimeouts.native.js.map +1 -1
- package/dist/esm/bundler/metaMaskConnectTimeouts.mjs +6 -0
- package/dist/esm/bundler/metaMaskConnectTimeouts.mjs.map +1 -1
- package/dist/esm/bundler/metaMaskConnectTimeouts.native.js +6 -0
- package/dist/esm/bundler/metaMaskConnectTimeouts.native.js.map +1 -1
- package/dist/jsx/bundler/metaMaskConnectTimeouts.mjs +6 -0
- package/dist/jsx/bundler/metaMaskConnectTimeouts.mjs.map +1 -1
- package/dist/jsx/bundler/metaMaskConnectTimeouts.native.js +6 -0
- package/dist/jsx/bundler/metaMaskConnectTimeouts.native.js.map +1 -1
- package/dist/keycloak/login.iife.js +1 -1
- package/package.json +7 -7
- package/src/bundler/metaMaskConnectTimeouts.spec.ts +131 -0
- package/src/bundler/metaMaskConnectTimeouts.ts +15 -0
- package/types/bundler/metaMaskConnectTimeouts.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/web3",
|
|
3
|
-
"version": "8.1
|
|
3
|
+
"version": "8.2.1",
|
|
4
4
|
"description": "Web3 wallet integration for multiplatform.one ecosystem with ConnectKit and wagmi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"connectkit",
|
|
@@ -120,10 +120,10 @@
|
|
|
120
120
|
"@aave/account": "^0.2.1",
|
|
121
121
|
"@coinbase/wallet-sdk": "^4.4.0",
|
|
122
122
|
"@metamask/connect-evm": "^2.1.1",
|
|
123
|
-
"@multiplatform.one/connectkit": "^8.1
|
|
124
|
-
"@multiplatform.one/gpg": "^8.1
|
|
125
|
-
"@multiplatform.one/platform": "^8.1
|
|
126
|
-
"@multiplatform.one/theme": "^8.1
|
|
123
|
+
"@multiplatform.one/connectkit": "^8.2.1",
|
|
124
|
+
"@multiplatform.one/gpg": "^8.2.1",
|
|
125
|
+
"@multiplatform.one/platform": "^8.2.1",
|
|
126
|
+
"@multiplatform.one/theme": "^8.2.1",
|
|
127
127
|
"@noble/ciphers": "^1.3.0",
|
|
128
128
|
"@noble/curves": "^1.9.7",
|
|
129
129
|
"@phosphor-icons/react": "^2.1.10",
|
|
@@ -147,8 +147,8 @@
|
|
|
147
147
|
"wagmi": "^3.7.1"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
|
-
"@multiplatform.one/config": "8.1
|
|
151
|
-
"@multiplatform.one/test-utils": "8.1
|
|
150
|
+
"@multiplatform.one/config": "8.2.1",
|
|
151
|
+
"@multiplatform.one/test-utils": "8.2.1",
|
|
152
152
|
"@tamagui/build": "2.7.6",
|
|
153
153
|
"@tanstack/react-query": "^5.104.3",
|
|
154
154
|
"@testing-library/jest-dom": "^7.0.1",
|
|
@@ -54,6 +54,12 @@ const iPadCheck =
|
|
|
54
54
|
|
|
55
55
|
const pageLoadResume =
|
|
56
56
|
/resumeSession_fn = function\(session, options\)[\s\S]*?isContinuingPriorAttempt \? this\.options\.resumeTimeout : options \? this\.options\.connectionTimeout : 120 \* 1e3/;
|
|
57
|
+
const extensionTimer = (seconds: number) =>
|
|
58
|
+
new RegExp(
|
|
59
|
+
`DEFAULT_REQUEST_TIMEOUT\\d* = ${seconds} \\* 1e3;\\s+var _notificationCallbacks\\d*, _transport\\d*, _defaultRequestOptions`,
|
|
60
|
+
"g",
|
|
61
|
+
);
|
|
62
|
+
|
|
57
63
|
const stockConnectionTimer =
|
|
58
64
|
/isContinuingPriorAttempt \? this\.options\.resumeTimeout : this\.options\.connectionTimeout/g;
|
|
59
65
|
|
|
@@ -85,6 +91,16 @@ describe("the timer patches on the installed MetaMask Connect", () => {
|
|
|
85
91
|
}
|
|
86
92
|
});
|
|
87
93
|
|
|
94
|
+
it("raises the desktop extension's request timer to 600 s", () => {
|
|
95
|
+
for (const file of multichainFiles) {
|
|
96
|
+
const code = read(file);
|
|
97
|
+
expect(code.match(extensionTimer(60))).toHaveLength(1);
|
|
98
|
+
const patched = patchMetaMaskConnectTimeouts(file, code)!.code;
|
|
99
|
+
expect(patched.match(extensionTimer(600))).toHaveLength(1);
|
|
100
|
+
expect(patched).not.toMatch(extensionTimer(60));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
88
104
|
it("gives only the option-less page-load resume the stock 120 s", () => {
|
|
89
105
|
for (const file of multichainFiles) {
|
|
90
106
|
const code = read(file);
|
|
@@ -149,6 +165,14 @@ describe("the timer patches on the installed MetaMask Connect", () => {
|
|
|
149
165
|
code.replace(/(DEFAULT_REQUEST_TIMEOUT\d*) = 60 \* 1e3;/, "$1 = 90 * 1e3;"),
|
|
150
166
|
),
|
|
151
167
|
).toThrow(/timer DEFAULT_REQUEST_TIMEOUT not found/);
|
|
168
|
+
expect(() =>
|
|
169
|
+
patchMetaMaskConnectTimeouts(
|
|
170
|
+
multichain!,
|
|
171
|
+
code.replace(extensionTimer(60), (match) => match.replace("60 * 1e3", "30 * 1e3")),
|
|
172
|
+
),
|
|
173
|
+
).toThrow(
|
|
174
|
+
/timer DefaultTransport DEFAULT_REQUEST_TIMEOUT not found .* would lose the ten-minute desktop extension confirmation/,
|
|
175
|
+
);
|
|
152
176
|
expect(() =>
|
|
153
177
|
patchMetaMaskConnectTimeouts(
|
|
154
178
|
dappClient!,
|
|
@@ -278,6 +302,107 @@ describe("the patched MetaMask Connect transport", () => {
|
|
|
278
302
|
});
|
|
279
303
|
});
|
|
280
304
|
|
|
305
|
+
type DefaultTransportClass = new () => {
|
|
306
|
+
sendEip1193Message(payload: { method: string; params?: unknown[] }): Promise<{ result: unknown }>;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
/** connect-multichain's desktop extension transport from its node build, patched or stock. */
|
|
310
|
+
function loadDefaultTransport(patched: boolean): DefaultTransportClass {
|
|
311
|
+
const file = requireHere.resolve(multichainPkg);
|
|
312
|
+
const code = patched ? patchMetaMaskConnectTimeouts(file, read(file))!.code : read(file);
|
|
313
|
+
const wrapper = runInThisContext(
|
|
314
|
+
`(function (module, exports, require, __filename, __dirname) {${code}\nreturn DefaultTransport;\n})`,
|
|
315
|
+
{ filename: file },
|
|
316
|
+
);
|
|
317
|
+
const module = { exports: {} };
|
|
318
|
+
return wrapper(module, module.exports, createRequire(file), file, dirname(file));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
describe("the desktop extension transport", () => {
|
|
322
|
+
const origin = "https://dev.promanager.vip";
|
|
323
|
+
|
|
324
|
+
/** A page with the MetaMask extension that holds every confirmation until told. */
|
|
325
|
+
function extensionPage() {
|
|
326
|
+
const listeners: ((event: unknown) => void)[] = [];
|
|
327
|
+
const sent: { id: string; method: string }[] = [];
|
|
328
|
+
vi.stubGlobal("location", { origin });
|
|
329
|
+
vi.stubGlobal("window", {
|
|
330
|
+
addEventListener: (type: string, listener: (event: unknown) => void) => {
|
|
331
|
+
if (type === "message") listeners.push(listener);
|
|
332
|
+
},
|
|
333
|
+
removeEventListener: vi.fn(),
|
|
334
|
+
postMessage: (message: { data: { data: { id: string; method: string } } }) =>
|
|
335
|
+
sent.push(message.data.data),
|
|
336
|
+
});
|
|
337
|
+
return {
|
|
338
|
+
sent,
|
|
339
|
+
confirm(id: string, result: string) {
|
|
340
|
+
const event = {
|
|
341
|
+
origin,
|
|
342
|
+
data: {
|
|
343
|
+
target: "metamask-inpage",
|
|
344
|
+
data: { name: "metamask-provider", data: { id, result } },
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
for (const listener of listeners) listener(event);
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function settle(promise: Promise<unknown>) {
|
|
353
|
+
const state: { value?: unknown; error?: unknown; settled: boolean } = { settled: false };
|
|
354
|
+
promise.then(
|
|
355
|
+
(value) => Object.assign(state, { settled: true, value }),
|
|
356
|
+
(error) => Object.assign(state, { settled: true, error }),
|
|
357
|
+
);
|
|
358
|
+
return state;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
afterEach(() => {
|
|
362
|
+
vi.useRealTimers();
|
|
363
|
+
vi.unstubAllGlobals();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("stock MetaMask Connect rejects a transaction still in MetaMask after 60 s", async () => {
|
|
367
|
+
vi.useFakeTimers();
|
|
368
|
+
extensionPage();
|
|
369
|
+
const DefaultTransport = loadDefaultTransport(false);
|
|
370
|
+
const send = settle(
|
|
371
|
+
new DefaultTransport().sendEip1193Message({ method: "eth_sendTransaction", params: [] }),
|
|
372
|
+
);
|
|
373
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
374
|
+
expect((send.error as Error | undefined)?.message).toBe("Request timeout");
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("resolves with the hash when the user confirms three minutes later", async () => {
|
|
378
|
+
vi.useFakeTimers();
|
|
379
|
+
const page = extensionPage();
|
|
380
|
+
const DefaultTransport = loadDefaultTransport(true);
|
|
381
|
+
const send = settle(
|
|
382
|
+
new DefaultTransport().sendEip1193Message({ method: "eth_sendTransaction", params: [] }),
|
|
383
|
+
);
|
|
384
|
+
await vi.advanceTimersByTimeAsync(180_000);
|
|
385
|
+
expect(send.settled).toBe(false);
|
|
386
|
+
expect(page.sent).toHaveLength(1);
|
|
387
|
+
page.confirm(page.sent[0]!.id, "0xhash");
|
|
388
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
389
|
+
expect(send.value).toMatchObject({ result: "0xhash" });
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("still gives up on a confirmation left open for ten minutes", async () => {
|
|
393
|
+
vi.useFakeTimers();
|
|
394
|
+
extensionPage();
|
|
395
|
+
const DefaultTransport = loadDefaultTransport(true);
|
|
396
|
+
const send = settle(
|
|
397
|
+
new DefaultTransport().sendEip1193Message({ method: "eth_sendTransaction", params: [] }),
|
|
398
|
+
);
|
|
399
|
+
await vi.advanceTimersByTimeAsync(599_999);
|
|
400
|
+
expect(send.settled).toBe(false);
|
|
401
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
402
|
+
expect((send.error as Error | undefined)?.message).toBe("Request timeout");
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
281
406
|
const userAgents = {
|
|
282
407
|
iPadSafari:
|
|
283
408
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15",
|
|
@@ -356,6 +481,12 @@ const renameGracePeriod: Plugin = {
|
|
|
356
481
|
function expectLongTimers(code: string) {
|
|
357
482
|
expect(code).toMatch(/DEFAULT_REQUEST_TIMEOUT[\w$]* = 600 \* 1e3;\s+CONNECTION_GRACE_PERIOD/);
|
|
358
483
|
expect(code).toMatch(/HANDSHAKE_TIMEOUT[\w$]* = 540 \* 1e3;/);
|
|
484
|
+
expect(code).toMatch(
|
|
485
|
+
/DEFAULT_REQUEST_TIMEOUT[\w$]* = 600 \* 1e3;\s+var _notificationCallbacks[\w$]*[,;]\s+(?:var )?_transport/,
|
|
486
|
+
);
|
|
487
|
+
expect(code).not.toMatch(
|
|
488
|
+
/DEFAULT_REQUEST_TIMEOUT[\w$]* = 60 \* 1e3;\s+var _notificationCallbacks/,
|
|
489
|
+
);
|
|
359
490
|
expect(code).toMatch(/resumeTimeout : [\w$]+ \? this\.options\.connectionTimeout : 120 \* 1e3/);
|
|
360
491
|
expect(code).not.toMatch(/DEFAULT_REQUEST_TIMEOUT[\w$]* = 60 \* 1e3;\s+CONNECTION_GRACE_PERIOD/);
|
|
361
492
|
expect(code).not.toMatch(/HANDSHAKE_TIMEOUT[\w$]* = 60 \* 1e3;/);
|
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
// until the user switches back; a user who lingered in MetaMask lost the request
|
|
8
8
|
// to those timers. Both become ten minutes (540 s + the 60 s session expiry).
|
|
9
9
|
//
|
|
10
|
+
// On desktop the extension transport (DefaultTransport, window.postMessage to
|
|
11
|
+
// MetaMask's content script) has its own 60 s request timer, also a module
|
|
12
|
+
// constant. A transaction that sat in MetaMask's confirmation longer than that
|
|
13
|
+
// was rejected as "Request timeout" while MetaMask still showed it, so a user
|
|
14
|
+
// who confirmed late paid and the app never got the hash. It gets the same
|
|
15
|
+
// ten minutes as the relay's request timer.
|
|
16
|
+
//
|
|
10
17
|
// The connection timer is the request timer plus 60 s, so it grows to 660 s with
|
|
11
18
|
// it. That is right for a connect the user is approving in MetaMask, but the same
|
|
12
19
|
// timer bounds resuming a stored session on page load, where nobody is in
|
|
@@ -31,6 +38,7 @@ export type MetaMaskConnectTimerRewrite = {
|
|
|
31
38
|
};
|
|
32
39
|
|
|
33
40
|
const longTimers = "the long Android timers";
|
|
41
|
+
const longExtensionTimer = "the ten-minute desktop extension confirmation";
|
|
34
42
|
|
|
35
43
|
export type MetaMaskConnectTimeoutPatch = {
|
|
36
44
|
pkg: string;
|
|
@@ -49,6 +57,13 @@ export const metaMaskConnectTimeoutPatches: readonly MetaMaskConnectTimeoutPatch
|
|
|
49
57
|
pattern: /(DEFAULT_REQUEST_TIMEOUT\d*) = 60 \* 1e3;(\s+CONNECTION_GRACE_PERIOD =)/,
|
|
50
58
|
replacement: "$1 = 600 * 1e3;$2",
|
|
51
59
|
},
|
|
60
|
+
{
|
|
61
|
+
target: "timer DefaultTransport DEFAULT_REQUEST_TIMEOUT",
|
|
62
|
+
lost: longExtensionTimer,
|
|
63
|
+
pattern:
|
|
64
|
+
/(DEFAULT_REQUEST_TIMEOUT\d*) = 60 \* 1e3;(\s+var _notificationCallbacks\d*, _transport\d*, _defaultRequestOptions\d*,)/,
|
|
65
|
+
replacement: "$1 = 600 * 1e3;$2",
|
|
66
|
+
},
|
|
52
67
|
{
|
|
53
68
|
target: "timer the page-load session resume",
|
|
54
69
|
lost: longTimers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metaMaskConnectTimeouts.d.ts","sourceRoot":"","sources":["../../src/bundler/metaMaskConnectTimeouts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metaMaskConnectTimeouts.d.ts","sourceRoot":"","sources":["../../src/bundler/metaMaskConnectTimeouts.ts"],"names":[],"mappings":"AA8BA,MAAM,MAAM,2BAA2B,GAAG;IACxC,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAKF,MAAM,MAAM,2BAA2B,GAAG;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,2BAA2B,EAAE,CAAC;CAClD,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,SAAS,2BAA2B,EA8C/E,CAAC;AAMF,2EAA2E;AAC3E,wBAAgB,8BAA8B,CAC5C,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACX,2BAA2B,GAAG,SAAS,CAKzC;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACX;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAY3C;AAED;;;GAGG;AACH,wBAAgB,mCAAmC;YAIvC,MAAM;cAGJ,MAAM,QAAQ,MAAM;aAzBxB,MAAM;cAAQ,MAAM;;IA+B1B,gFAAgF;eACrE,MAAM,GAAG,SAAS;EAShC"}
|