diff --git a/packages/core/src/controllers/pairing.ts b/packages/core/src/controllers/pairing.ts index e1a81fbe9..e7d023024 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, toMiliseconds } from "@walletconnect/time"; import EventEmitter from "events"; import { PAIRING_CONTEXT, @@ -187,14 +187,18 @@ export class Pairing implements IPairing { public activate: IPairing["activate"] = async ({ topic }) => { this.isInitialized(); - const expiry = calcExpiry(THIRTY_DAYS); + const expiry = calcExpiry(FIVE_MINUTES); this.core.expirer.set(topic, expiry); 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); + 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 f6e9dc11d..265ebb494 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 } from "@walletconnect/time"; const createCoreClients: () => Promise<{ coreA: ICore; coreB: ICore }> = async () => { const coreA = new Core(TEST_CORE_OPTIONS); @@ -121,8 +122,12 @@ 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); + // inactive pairing should have an expiry of 5 minutes + expect(inactivePairing.expiry).to.be.approximately(calcExpiry(FIVE_MINUTES), 5); + // active pairing should still have an expiry of 5 minutes + expect(activePairing.expiry).to.be.approximately(calcExpiry(FIVE_MINUTES), 5); }); }); diff --git a/packages/sign-client/src/controllers/engine.ts b/packages/sign-client/src/controllers/engine.ts index e8890df91..a8eb38f02 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 249b2bf94..726a256f9 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));