Skip to content

Commit

Permalink
Merge pull request #3632 from WalletConnect/feat/store-verify-context
Browse files Browse the repository at this point in the history
feat: `verifyContext` in pending request store
  • Loading branch information
ganchoradkov authored Sep 12, 2023
2 parents cfc76fb + e8610e7 commit 7a8ba84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
25 changes: 13 additions & 12 deletions packages/sign-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,12 @@ export class Engine extends IEngine {
pendingRequest: PendingRequestTypes.Struct,
) => {
const expiry = ENGINE_RPC_OPTS.wc_sessionRequest.req.ttl;
const { id, topic, params } = pendingRequest;
const { id, topic, params, verifyContext } = pendingRequest;
await this.client.pendingRequest.set(id, {
id,
topic,
params,
verifyContext,
});
if (expiry) this.client.core.expirer.set(id, calcExpiry(expiry));
};
Expand Down Expand Up @@ -973,9 +974,15 @@ export class Engine extends IEngine {
const { id, params } = payload;
try {
this.isValidRequest({ topic, ...params });
await this.setPendingSessionRequest({ id, topic, params });
this.addSessionRequestToSessionRequestQueue({ id, topic, params });
await this.processSessionRequestQueue();
const hash = hashMessage(
JSON.stringify(formatJsonRpcRequest("wc_sessionRequest", params, id)),
);
const session = this.client.session.get(topic);
const verifyContext = await this.getVerifyContext(hash, session.peer.metadata);
const request = { id, topic, params, verifyContext };
await this.setPendingSessionRequest(request);
this.addSessionRequestToSessionRequestQueue(request);
this.processSessionRequestQueue();
} catch (err: any) {
await this.sendError(id, topic, err);
this.client.logger.error(err);
Expand Down Expand Up @@ -1033,7 +1040,7 @@ export class Engine extends IEngine {
}, toMiliseconds(this.requestQueueDelay));
};

private processSessionRequestQueue = async () => {
private processSessionRequestQueue = () => {
if (this.sessionRequestQueue.state === ENGINE_QUEUE_STATES.active) {
this.client.logger.info("session request queue is already active.");
return;
Expand All @@ -1046,14 +1053,8 @@ export class Engine extends IEngine {
}

try {
const { id, topic, params } = request;
const hash = hashMessage(
JSON.stringify(formatJsonRpcRequest("wc_sessionRequest", params, id)),
);
const session = this.client.session.get(topic);
const verifyContext = await this.getVerifyContext(hash, session.peer.metadata);
this.sessionRequestQueue.state = ENGINE_QUEUE_STATES.active;
this.client.events.emit("session_request", { id, topic, params, verifyContext });
this.client.events.emit("session_request", request);
} catch (error) {
this.client.logger.error(error);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/sign-client/pendingRequest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { IStore } from "../core";
import { IStore, Verify } from "../core";
import { JsonRpcTypes } from "./jsonrpc";

export declare namespace PendingRequestTypes {
export interface Struct {
topic: string;
id: number;
params: JsonRpcTypes.RequestParams["wc_sessionRequest"];
verifyContext: Verify.Context;
}
}
export type IPendingRequest = IStore<number, PendingRequestTypes.Struct>;

0 comments on commit 7a8ba84

Please sign in to comment.