Skip to content

Commit

Permalink
Merge pull request #5582 from WalletConnect/chore/pairing-methods-dep…
Browse files Browse the repository at this point in the history
…recation-notice

chore: adds deprecation notice on pairing methods and reduces expiry …
  • Loading branch information
ganchoradkov authored Jan 17, 2025
2 parents 7f1bbac + 1fbb671 commit c932adc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/controllers/pairing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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", {});
Expand Down
11 changes: 8 additions & 3 deletions packages/core/test/pairing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});

Expand Down
7 changes: 6 additions & 1 deletion packages/sign-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 });
}
};
Expand Down
7 changes: 4 additions & 3 deletions packages/sign-client/test/sdk/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("Authenticated Sessions", () => {
name: "wallet",
metadata: TEST_APP_METADATA_B,
});
await Promise.all([
const result = await Promise.all([
Promise.race<void>([
new Promise((resolve) => {
wallet.on("session_authenticate", async (payload) => {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit c932adc

Please sign in to comment.