From 1479ba218fb36ddbcc876c367545482bb977194b Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 8 Jan 2025 11:00:27 +0200 Subject: [PATCH 1/4] chore: adds deprecation notice on pairing methods and reduces expiry of active pairings from 30days to 1minute --- packages/core/src/controllers/pairing.ts | 4 ++-- packages/sign-client/src/controllers/engine.ts | 7 ++++++- packages/sign-client/test/sdk/auth.spec.ts | 7 ++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/core/src/controllers/pairing.ts b/packages/core/src/controllers/pairing.ts index e1a81fbe9b..2fd1ae77c9 100644 --- a/packages/core/src/controllers/pairing.ts +++ b/packages/core/src/controllers/pairing.ts @@ -35,7 +35,7 @@ import { isJsonRpcResult, isJsonRpcError, } from "@walletconnect/jsonrpc-utils"; -import { FIVE_MINUTES, THIRTY_DAYS, toMiliseconds } from "@walletconnect/time"; +import { FIVE_MINUTES, ONE_MINUTE, toMiliseconds } from "@walletconnect/time"; import EventEmitter from "events"; import { PAIRING_CONTEXT, @@ -187,7 +187,7 @@ export class Pairing implements IPairing { public activate: IPairing["activate"] = async ({ topic }) => { this.isInitialized(); - const expiry = calcExpiry(THIRTY_DAYS); + const expiry = calcExpiry(ONE_MINUTE); this.core.expirer.set(topic, expiry); await this.pairings.update(topic, { active: true, expiry }); }; diff --git a/packages/sign-client/src/controllers/engine.ts b/packages/sign-client/src/controllers/engine.ts index e8890df91a..a8eb38f022 100644 --- a/packages/sign-client/src/controllers/engine.ts +++ b/packages/sign-client/src/controllers/engine.ts @@ -182,10 +182,12 @@ export class Engine extends IEngine { let topic = pairingTopic; let uri: string | undefined; let active = false; - try { if (topic) { const pairing = this.client.core.pairing.pairings.get(topic); + this.client.logger.warn( + "connect() with existing pairing topic is deprecated and will be removed in the next major release.", + ); active = pairing.active; } } catch (error) { @@ -681,6 +683,9 @@ export class Engine extends IEngine { done(), ]); } else if (this.client.core.pairing.pairings.keys.includes(topic)) { + this.client.logger.warn( + "ping() on pairing topic is deprecated and will be removed in the next major release.", + ); await this.client.core.pairing.ping({ topic }); } }; diff --git a/packages/sign-client/test/sdk/auth.spec.ts b/packages/sign-client/test/sdk/auth.spec.ts index 249b2bf94a..726a256f9f 100644 --- a/packages/sign-client/test/sdk/auth.spec.ts +++ b/packages/sign-client/test/sdk/auth.spec.ts @@ -45,7 +45,7 @@ describe("Authenticated Sessions", () => { name: "wallet", metadata: TEST_APP_METADATA_B, }); - await Promise.all([ + const result = await Promise.all([ Promise.race([ new Promise((resolve) => { wallet.on("session_authenticate", async (payload) => { @@ -110,8 +110,9 @@ describe("Authenticated Sessions", () => { wallet.pair({ uri }); resolve(); }), - ]); - const session = (await response()).session; + response(), + ]).then((res) => res[2]); + const session = result.session; const walletSession = wallet.session.get(session.topic); // approved namespaces on both sides must be equal expect(JSON.stringify(session.namespaces)).to.eq(JSON.stringify(walletSession.namespaces)); From 051e58775cd01758fbf85f3ab6dc8e52fdc4d92d Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 8 Jan 2025 11:18:12 +0200 Subject: [PATCH 2/4] chore: tests --- packages/core/test/pairing.spec.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/core/test/pairing.spec.ts b/packages/core/test/pairing.spec.ts index f6e9dc11d2..b2279e3064 100644 --- a/packages/core/test/pairing.spec.ts +++ b/packages/core/test/pairing.spec.ts @@ -2,7 +2,8 @@ import { expect, describe, it, beforeEach, afterEach } from "vitest"; import { ICore } from "@walletconnect/types"; import { Core, CORE_PROTOCOL, CORE_VERSION, PAIRING_EVENTS, SUBSCRIBER_EVENTS } from "../src"; import { TEST_CORE_OPTIONS, disconnectSocket, waitForEvent } from "./shared"; -import { generateRandomBytes32, parseUri, toBase64 } from "@walletconnect/utils"; +import { calcExpiry, generateRandomBytes32, parseUri, toBase64 } from "@walletconnect/utils"; +import { FIVE_MINUTES, ONE_MINUTE } from "@walletconnect/time"; const createCoreClients: () => Promise<{ coreA: ICore; coreB: ICore }> = async () => { const coreA = new Core(TEST_CORE_OPTIONS); @@ -121,8 +122,13 @@ describe("Pairing", () => { const inactivePairing = coreA.pairing.pairings.get(topic); expect(inactivePairing.active).toBe(false); await coreA.pairing.activate({ topic }); - expect(coreA.pairing.pairings.get(topic).active).toBe(true); - expect(coreA.pairing.pairings.get(topic).expiry > inactivePairing.expiry).toBe(true); + const activePairing = coreA.pairing.pairings.get(topic); + expect(activePairing.active).toBe(true); + expect(activePairing.expiry > inactivePairing.expiry).toBe(false); + // inactive pairing should have an expiry of 5 minutes + expect(inactivePairing.expiry).to.be.approximately(calcExpiry(FIVE_MINUTES), 5); + // active pairing should have an expiry of 1 minute + expect(activePairing.expiry).to.be.approximately(calcExpiry(ONE_MINUTE), 5); }); }); From b478e37be2d7170aed05283d1c8beffaed2c53a9 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 8 Jan 2025 12:00:32 +0200 Subject: [PATCH 3/4] refactor: sets active pairing expiry of 5mins --- packages/core/src/controllers/pairing.ts | 5 +++-- packages/core/test/pairing.spec.ts | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/src/controllers/pairing.ts b/packages/core/src/controllers/pairing.ts index 2fd1ae77c9..f844156c45 100644 --- a/packages/core/src/controllers/pairing.ts +++ b/packages/core/src/controllers/pairing.ts @@ -35,7 +35,7 @@ import { isJsonRpcResult, isJsonRpcError, } from "@walletconnect/jsonrpc-utils"; -import { FIVE_MINUTES, ONE_MINUTE, toMiliseconds } from "@walletconnect/time"; +import { FIVE_MINUTES, toMiliseconds } from "@walletconnect/time"; import EventEmitter from "events"; import { PAIRING_CONTEXT, @@ -187,7 +187,7 @@ export class Pairing implements IPairing { public activate: IPairing["activate"] = async ({ topic }) => { this.isInitialized(); - const expiry = calcExpiry(ONE_MINUTE); + const expiry = calcExpiry(FIVE_MINUTES); this.core.expirer.set(topic, expiry); await this.pairings.update(topic, { active: true, expiry }); }; @@ -195,6 +195,7 @@ export class Pairing implements IPairing { public ping: IPairing["ping"] = async (params) => { this.isInitialized(); await this.isValidPing(params); + this.logger.warn("ping() is deprecated and will be removed in the next major release."); const { topic } = params; if (this.pairings.keys.includes(topic)) { const id = await this.sendRequest(topic, "wc_pairingPing", {}); diff --git a/packages/core/test/pairing.spec.ts b/packages/core/test/pairing.spec.ts index b2279e3064..265ebb4949 100644 --- a/packages/core/test/pairing.spec.ts +++ b/packages/core/test/pairing.spec.ts @@ -3,7 +3,7 @@ import { ICore } from "@walletconnect/types"; import { Core, CORE_PROTOCOL, CORE_VERSION, PAIRING_EVENTS, SUBSCRIBER_EVENTS } from "../src"; import { TEST_CORE_OPTIONS, disconnectSocket, waitForEvent } from "./shared"; import { calcExpiry, generateRandomBytes32, parseUri, toBase64 } from "@walletconnect/utils"; -import { FIVE_MINUTES, ONE_MINUTE } from "@walletconnect/time"; +import { FIVE_MINUTES } from "@walletconnect/time"; const createCoreClients: () => Promise<{ coreA: ICore; coreB: ICore }> = async () => { const coreA = new Core(TEST_CORE_OPTIONS); @@ -124,11 +124,10 @@ describe("Pairing", () => { await coreA.pairing.activate({ topic }); const activePairing = coreA.pairing.pairings.get(topic); expect(activePairing.active).toBe(true); - expect(activePairing.expiry > inactivePairing.expiry).toBe(false); // inactive pairing should have an expiry of 5 minutes expect(inactivePairing.expiry).to.be.approximately(calcExpiry(FIVE_MINUTES), 5); - // active pairing should have an expiry of 1 minute - expect(activePairing.expiry).to.be.approximately(calcExpiry(ONE_MINUTE), 5); + // active pairing should still have an expiry of 5 minutes + expect(activePairing.expiry).to.be.approximately(calcExpiry(FIVE_MINUTES), 5); }); }); From 1fbb67165b899d24a2f0b966ee9fa23c87a0a757 Mon Sep 17 00:00:00 2001 From: Gancho Radkov <43912948+ganchoradkov@users.noreply.github.com> Date: Fri, 17 Jan 2025 09:33:11 +0200 Subject: [PATCH 4/4] chore: adds deprecation warning --- packages/core/src/controllers/pairing.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/core/src/controllers/pairing.ts b/packages/core/src/controllers/pairing.ts index f844156c45..e7d0230241 100644 --- a/packages/core/src/controllers/pairing.ts +++ b/packages/core/src/controllers/pairing.ts @@ -192,6 +192,9 @@ export class Pairing implements IPairing { await this.pairings.update(topic, { active: true, expiry }); }; + /** + * @deprecated Ping will be removed in the next major release. + */ public ping: IPairing["ping"] = async (params) => { this.isInitialized(); await this.isValidPing(params);