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

feat: tg mini apps support #5403

Merged
merged 15 commits into from
Oct 1, 2024
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
185 changes: 93 additions & 92 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion packages/core/src/controllers/pairing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Pairing implements IPairing {
const topic = await this.core.crypto.setSymKey(symKey);
const expiry = calcExpiry(FIVE_MINUTES);
const relay = { protocol: RELAYER_DEFAULT_PROTOCOL };
const pairing = { topic, expiry, relay, active: false };
const pairing = { topic, expiry, relay, active: false, methods: params?.methods };
const uri = formatUri({
protocol: this.core.protocol,
version: this.core.version,
Expand All @@ -106,6 +106,7 @@ export class Pairing implements IPairing {
expiryTimestamp: expiry,
methods: params?.methods,
});
this.events.emit(PAIRING_EVENTS.create, pairing);
this.core.expirer.set(topic, expiry);
await this.pairings.set(topic, pairing);
await this.core.relayer.subscribe(topic, { transportType: params?.transportType });
Expand Down Expand Up @@ -231,6 +232,21 @@ export class Pairing implements IPairing {
}
};

public formatUriFromPairing: IPairing["formatUriFromPairing"] = (pairing) => {
this.isInitialized();
const { topic, relay, expiry, methods } = pairing;
const symKey = this.core.crypto.keychain.get(topic);
return formatUri({
protocol: this.core.protocol,
version: this.core.version,
topic,
symKey,
relay,
expiryTimestamp: expiry,
methods,
});
};

// ---------- Private Helpers ----------------------------------------------- //

private sendRequest: IPairingPrivate["sendRequest"] = async (topic, method, params) => {
Expand Down
16 changes: 16 additions & 0 deletions packages/core/test/pairing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ describe("Pairing", () => {
});
});

describe("formatUriFromPairing", () => {
it("should generate pairing uri from pairing", async () => {
let generatedUri = "";
coreA.pairing.events.once("pairing_create", (payload) => {
generatedUri = coreA.pairing.formatUriFromPairing(payload);
});
const { uri } = await coreA.pairing.create({
methods: ["eth_sendTransaction", "personal_sign"],
});
expect(generatedUri).to.be.eq(uri);
const parsedUri = parseUri(uri);
const parsedGeneratedUri = parseUri(generatedUri);
expect(parsedGeneratedUri).to.deep.equal(parsedUri);
});
});

describe("ping", () => {
it("clients can ping each other", async () => {
const { uri, topic } = await coreA.pairing.create();
Expand Down
6 changes: 3 additions & 3 deletions packages/sign-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@
new Promise<void>(async (resolve) => {
// only attempt to handle deeplinks if they are not explicitly disabled in the session config
if (!session.sessionConfig?.disableDeepLink) {
const wcDeepLink = await getDeepLink(
const wcDeepLink = (await getDeepLink(
this.client.core.storage,
WALLETCONNECT_DEEPLINK_CHOICE,
);
handleDeeplinkRedirect({ id: clientRpcId, topic, wcDeepLink });
)) as string;
await handleDeeplinkRedirect({ id: clientRpcId, topic, wcDeepLink });
}
resolve();
}),
Expand Down Expand Up @@ -2076,7 +2076,7 @@
}, 500);
};

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

Check warning on line 2079 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
Loading
Loading