Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adds deprecation notice on pairing methods and reduces expiry … #5582

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
ganchoradkov marked this conversation as resolved.
Show resolved Hide resolved
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 @@
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 @@
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.",
ganchoradkov marked this conversation as resolved.
Show resolved Hide resolved
);
await this.client.core.pairing.ping({ topic });
}
};
Expand Down Expand Up @@ -2079,7 +2084,7 @@
}, 500);
};

private onSessionDeleteRequest: EnginePrivate["onSessionDeleteRequest"] = async (

Check warning on line 2087 in packages/sign-client/src/controllers/engine.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Async method 'onSessionDeleteRequest' has no 'await' expression
topic,
payload,
) => {
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
Loading