From f3c713fc183c731d18d4e929f209e4e07450d647 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Tue, 5 Mar 2024 15:06:03 +0200 Subject: [PATCH 1/9] refactor: removes redundant calls --- src/controllers/engine.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/controllers/engine.ts b/src/controllers/engine.ts index fa2793a..2036df3 100644 --- a/src/controllers/engine.ts +++ b/src/controllers/engine.ts @@ -106,20 +106,25 @@ export class Engine extends ISingleEthereumEngine { const formattedChain = prefixChainWithNamespace(chainId); const formattedAccounts = formatAccounts(accounts, chainId); const namespaces = session.namespaces[EVM_IDENTIFIER]; + let shouldUpdateSession = false; if (!chainAlreadyInSession(session, chainId)) { namespaces?.chains?.push(formattedChain); + shouldUpdateSession = true; } if (!accountsAlreadyInSession(session, formattedAccounts)) { namespaces.accounts = namespaces.accounts.concat(formattedAccounts); + shouldUpdateSession = true; } - await this.web3wallet.updateSession({ - topic, - namespaces: { - [EVM_IDENTIFIER]: namespaces, - }, - }); + if (shouldUpdateSession) { + await this.web3wallet.updateSession({ + topic, + namespaces: { + [EVM_IDENTIFIER]: namespaces, + }, + }); + } if (this.chainId !== chainId) { await this.changeChain(topic, chainId); @@ -293,7 +298,6 @@ export class Engine extends ISingleEthereumEngine { }; private changeChain = async (topic: string, chainId: number) => { - await this.web3wallet.engine.signClient.ping({ topic }); await this.web3wallet.emitSessionEvent({ topic, event: { From 07784e3da14ba7da7e66afd6de82a5dea1e0f5d6 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Sun, 10 Mar 2024 14:37:37 +0200 Subject: [PATCH 2/9] chore: updates w3wallet --- package.json | 2 +- yarn.lock | 60 ++++++++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index c129743..47a6862 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "install:all": "yarn && cd ./examples/dapp && yarn && cd ./../wallet && yarn" }, "dependencies": { - "@walletconnect/web3wallet": "1.10.0" + "@walletconnect/web3wallet": "1.10.2" }, "devDependencies": { "@ethersproject/wallet": "^5.7.0", diff --git a/yarn.lock b/yarn.lock index bbc405c..58e6344 100644 --- a/yarn.lock +++ b/yarn.lock @@ -918,10 +918,10 @@ events "^3.3.0" isomorphic-unfetch "^3.1.0" -"@walletconnect/core@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.0.tgz#3a4e301077b2f858fd916b7a20b5b984d1afce63" - integrity sha512-2Tjp5BCevI7dbmqo/OrCjX4tqgMqwJNQLlQAlphqPfvwlF9+tIu6pGcVbSN3U9zyXzWIZCeleqEaWUeSeET4Ew== +"@walletconnect/core@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.2.tgz#35286be92c645fa461fecc0dfe25de9f076fca8f" + integrity sha512-bB4SiXX8hX3/hyBfVPC5gwZCXCl+OPj+/EDVM71iAO3TDsh78KPbrVAbDnnsbHzZVHlsMohtXX3j5XVsheN3+g== dependencies: "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-provider" "1.0.13" @@ -934,8 +934,8 @@ "@walletconnect/relay-auth" "^1.0.4" "@walletconnect/safe-json" "^1.0.2" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" events "^3.3.0" isomorphic-unfetch "3.1.0" lodash.isequal "4.5.0" @@ -1086,19 +1086,19 @@ dependencies: tslib "1.14.1" -"@walletconnect/sign-client@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.0.tgz#de10f976cc1b8ab04b7f7c27f6a298e4e083ab25" - integrity sha512-H2ukscibBS+6WrzQWh+WyVBqO5z4F5et12JcwobdwgHnJSlqIoZxqnUYYWNCI5rUR5UKsKWaUyto4AE9N5dw4Q== +"@walletconnect/sign-client@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.2.tgz#855609653855f0d23b0502cdbdcf43402e34c459" + integrity sha512-MfBcuSz2GmMH+P7MrCP46mVE5qhP0ZyWA0FyIH6/WuxQ6G+MgKsGfaITqakpRPsykWOJq8tXMs3XvUPDU413OQ== dependencies: - "@walletconnect/core" "2.11.0" + "@walletconnect/core" "2.11.2" "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "^2.0.1" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" events "^3.3.0" "@walletconnect/time@^1.0.2": @@ -1120,10 +1120,10 @@ "@walletconnect/logger" "^2.0.1" events "^3.3.0" -"@walletconnect/types@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.0.tgz#474a009c56faa9ef4063b76ed84415c801dc9f1e" - integrity sha512-AB5b1lrEbCGHxqS2vqfCkIoODieH+ZAUp9rA1O2ftrhnqDJiJK983Df87JhYhECsQUBHHfALphA8ydER0q+9sw== +"@walletconnect/types@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.2.tgz#d0359dd4106fcaa1634241a00428d3ea08d0d3c7" + integrity sha512-p632MFB+lJbip2cvtXPBQslpUdiw1sDtQ5y855bOlAGquay+6fZ4h1DcDePeKQDQM3P77ax2a9aNPZxV6y/h1Q== dependencies: "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" @@ -1152,10 +1152,10 @@ query-string "7.1.3" uint8arrays "^3.1.0" -"@walletconnect/utils@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.0.tgz#31c95151c823022077883dda61800cdea71879b7" - integrity sha512-hxkHPlTlDQILHfIKXlmzgNJau/YcSBC3XHUSuZuKZbNEw3duFT6h6pm3HT/1+j1a22IG05WDsNBuTCRkwss+BQ== +"@walletconnect/utils@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.2.tgz#dee0f19adf5e38543612cbe9fa4de7ed28eb7e85" + integrity sha512-LyfdmrnZY6dWqlF4eDrx5jpUwsB2bEPjoqR5Z6rXPiHJKUOdJt7az+mNOn5KTSOlRpd1DmozrBrWr+G9fFLYVw== dependencies: "@stablelib/chacha20poly1305" "1.0.1" "@stablelib/hkdf" "1.0.1" @@ -1165,26 +1165,26 @@ "@walletconnect/relay-api" "^1.0.9" "@walletconnect/safe-json" "^1.0.2" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" + "@walletconnect/types" "2.11.2" "@walletconnect/window-getters" "^1.0.1" "@walletconnect/window-metadata" "^1.0.1" detect-browser "5.3.0" query-string "7.1.3" uint8arrays "^3.1.0" -"@walletconnect/web3wallet@1.10.0": - version "1.10.0" - resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.0.tgz#5a7f181bbea213e8fb5961900a0069e58da36d18" - integrity sha512-JyaYdnBKL1hVpsE5hpjZhohpX1Ak2mwai3GYr8nI1FfK8Z3IPIh+4ImeDMnEao1cQFoItQNompp5y5C7WlI69A== +"@walletconnect/web3wallet@1.10.2": + version "1.10.2" + resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.2.tgz#5887642773e6e1b88d1bfb159a00ec45b31f762a" + integrity sha512-FbWsJwhihppl6poJ0+0WCkjXZDVdb11KJiS/AJt+qyNheIKQ7z6NfCnCnnKPBEpNNoUPclcFo4b/BmdFo2YlMw== dependencies: "@walletconnect/auth-client" "2.1.2" - "@walletconnect/core" "2.11.0" + "@walletconnect/core" "2.11.2" "@walletconnect/jsonrpc-provider" "1.0.13" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "2.0.1" - "@walletconnect/sign-client" "2.11.0" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/sign-client" "2.11.2" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" "@walletconnect/window-getters@^1.0.1": version "1.0.1" From dd7890c6b856cc487cf7c7ea95e1bf4bf178d2c4 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Sun, 10 Mar 2024 14:38:15 +0200 Subject: [PATCH 3/9] refactor: updates session with active chain and removes other approved chains --- src/controllers/engine.ts | 82 +++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/src/controllers/engine.ts b/src/controllers/engine.ts index 2036df3..3394ac0 100644 --- a/src/controllers/engine.ts +++ b/src/controllers/engine.ts @@ -26,6 +26,8 @@ export class Engine extends ISingleEthereumEngine { reject: (value?: T | PromiseLike) => void; }[] = []; + private switchChainTimeout: NodeJS.Timeout | undefined; + constructor(client: ISingleEthereumEngine["client"]) { super(client); // initialized in init() @@ -41,7 +43,7 @@ export class Engine extends ISingleEthereumEngine { }; public pair: ISingleEthereumEngine["pair"] = async (params) => { - await this.client.core.pairing.pair(params); + await this.web3wallet.pair(params); }; public approveSession: ISingleEthereumEngine["approveSession"] = async (params) => { @@ -49,14 +51,11 @@ export class Engine extends ISingleEthereumEngine { const proposal = this.web3wallet.engine.signClient.proposal.get(id); const normalizedRequired = normalizeNamespaces(proposal.requiredNamespaces); const normalizedOptional = normalizeNamespaces(proposal.optionalNamespaces); - const requiredChain = normalizedRequired[EVM_IDENTIFIER]?.chains?.[0]; - const requiredParsed = requiredChain ? parseInt(parseChain(requiredChain)) : chainId; - const approvedChains = [requiredParsed]; - - if (requiredParsed !== chainId) { - approvedChains.push(chainId); - } - + const requiredChains = (normalizedRequired[EVM_IDENTIFIER]?.chains || []).map((chain) => { + const parsed = parseChain(chain); + return parseInt(parsed); + }); + const approvedChains = [...new Set([chainId, ...requiredChains])]; const approveParams = { id, namespaces: { @@ -86,8 +85,8 @@ export class Engine extends ISingleEthereumEngine { const session = await this.web3wallet.approveSession(approveParams); this.chainId = chainId; // emit chainChanged if a different chain is approved other than the required - if (approvedChains.length > 1) { - setTimeout(() => this.changeChain(session.topic, chainId), 2_000); + if (chainId !== requiredChains?.[0]) { + this.switchChainTimeout = setTimeout(() => this.changeChain(session.topic, chainId), 2_000); } return session; @@ -108,22 +107,38 @@ export class Engine extends ISingleEthereumEngine { const namespaces = session.namespaces[EVM_IDENTIFIER]; let shouldUpdateSession = false; if (!chainAlreadyInSession(session, chainId)) { - namespaces?.chains?.push(formattedChain); + const requiredChains = session.requiredNamespaces?.[EVM_IDENTIFIER]?.chains || []; + namespaces.chains = [formattedChain, ...requiredChains]; shouldUpdateSession = true; } if (!accountsAlreadyInSession(session, formattedAccounts)) { - namespaces.accounts = namespaces.accounts.concat(formattedAccounts); + namespaces.accounts = + namespaces.chains + ?.map((chain) => formatAccounts(accounts, parseInt(parseChain(chain)))) + .flat() || []; shouldUpdateSession = true; } if (shouldUpdateSession) { - await this.web3wallet.updateSession({ - topic, - namespaces: { - [EVM_IDENTIFIER]: namespaces, - }, - }); + await Promise.all([ + new Promise((resolve) => { + // wait for relayer to publish the update before emitting events + const onPublish = (params: { topic: string }) => { + if (params.topic === topic) { + this.web3wallet.core.relayer.off("relayer_publish", onPublish); + resolve(); + } + }; + this.web3wallet.core.relayer.on("relayer_publish", onPublish); + }), + this.web3wallet.updateSession({ + topic, + namespaces: { + [EVM_IDENTIFIER]: namespaces, + }, + }), + ]); } if (this.chainId !== chainId) { @@ -230,9 +245,13 @@ export class Engine extends ISingleEthereumEngine { this.client.logger.info( `Session request chainId ${event.params.chainId} does not match current chainId ${this.chainId}. Attempting to switch`, ); - await this.switchEthereumChain(event).catch((e) => { + try { + await this.switchEthereumChain(event); + } catch (e) { this.client.logger.warn(e); - }); + const error = getSdkError("USER_REJECTED"); + return this.rejectRequest({ id: event.id, topic: event.topic, error }); + } } // delay session request to allow for chain switch to complete setTimeout(() => this.client.events.emit("session_request", event), 1_000); @@ -298,14 +317,19 @@ export class Engine extends ISingleEthereumEngine { }; private changeChain = async (topic: string, chainId: number) => { - await this.web3wallet.emitSessionEvent({ - topic, - event: { - name: "chainChanged", - data: chainId, - }, - chainId: prefixChainWithNamespace(chainId), - }); + try { + clearTimeout(this.switchChainTimeout); + await this.web3wallet.emitSessionEvent({ + topic, + event: { + name: "chainChanged", + data: chainId, + }, + chainId: prefixChainWithNamespace(chainId), + }); + } catch (e) { + this.client.logger.warn(e); + } }; private switchEthereumChain = async (event: SingleEthereumTypes.SessionRequest) => { From 1a9058662e8705f4690a2744cf5476c0d59e3831 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Sun, 10 Mar 2024 14:38:26 +0200 Subject: [PATCH 4/9] feat: tests --- test/shared/values.ts | 2 +- test/sign.spec.ts | 130 ++++++++++++++++++++++++++++++------------ 2 files changed, 95 insertions(+), 37 deletions(-) diff --git a/test/shared/values.ts b/test/shared/values.ts index 4408ac5..8113892 100644 --- a/test/shared/values.ts +++ b/test/shared/values.ts @@ -34,7 +34,7 @@ export const TEST_NAMESPACES = { export const TEST_UPDATED_NAMESPACES = { eip155: { methods: TEST_METHODS.concat(TEST_OPTIONAL_METHODS), - accounts: [TEST_ETHEREUM_ACCOUNT, TEST_GOERLI_ACCOUNT], + accounts: [TEST_GOERLI_ACCOUNT, TEST_ETHEREUM_ACCOUNT], events: TEST_EVENTS, }, }; diff --git a/test/sign.spec.ts b/test/sign.spec.ts index 3227b1d..132803c 100644 --- a/test/sign.spec.ts +++ b/test/sign.spec.ts @@ -261,6 +261,76 @@ describe("Sign Integration", () => { ]); }); + it("should replace approved chainId on update", async () => { + dapp = await SignClient.init({ + ...TEST_CORE_OPTIONS, + name: "Dapp", + }); + const { uri, approval } = await dapp.connect({ + optionalNamespaces: TEST_OPTIONAL_NAMESPACES, + }); + sessionApproval = approval; + uriString = uri || ""; + let session; + wallet = await SingleEthereum.init({ + core, + name: "wallet", + metadata: {} as any, + }); + + // first pair and approve session + await Promise.all([ + new Promise((resolve) => { + wallet.on("session_proposal", async (sessionProposal) => { + const { id, params } = sessionProposal; + session = await wallet.approveSession({ + id, + chainId: TEST_ETHEREUM_CHAIN_PARSED, + accounts: [cryptoWallet.address], + }); + resolve(session); + }); + }), + sessionApproval(), + wallet.pair({ uri: uriString }), + ]); + await Promise.all([ + new Promise((resolve) => { + dapp.events.once("session_update", (session) => { + const { params } = session; + expect(params.namespaces.eip155.chains).to.toMatchObject([ + `${EVM_IDENTIFIER}:${TEST_GOERLI_CHAIN_PARSED}`, + ]); + resolve(session); + }); + }), + wallet.updateSession({ + topic: session.topic, + chainId: TEST_GOERLI_CHAIN_PARSED, + accounts: [TEST_ETHEREUM_ADDRESS], + }), + ]); + await new Promise((resolve) => setTimeout(resolve, 1000)); + await Promise.all([ + new Promise((resolve) => { + dapp.events.once("session_update", (session) => { + const { params } = session; + expect(params.namespaces.eip155.chains).to.toMatchObject([ + `${EVM_IDENTIFIER}:${TEST_ETHEREUM_CHAIN_PARSED}`, + ]); + resolve(session); + }); + }), + wallet.updateSession({ + topic: session.topic, + chainId: TEST_ETHEREUM_CHAIN_PARSED, + accounts: [TEST_ETHEREUM_ADDRESS], + }), + ]); + + await new Promise((resolve) => setTimeout(resolve, 1000)); + }); + it("should request wallet_switchEthereumChain to session request in different chain", async () => { // first pair and approve session await Promise.all([ @@ -385,44 +455,32 @@ describe("Sign Integration", () => { resolve(); } }); - wallet.on("session_request", async (sessionRequest) => { - const { id, params, verifyContext } = sessionRequest; - if (params.request.method === "wallet_switchEthereumChain") return; - expect(verifyContext).to.be.exist; - expect(verifyContext.verified.validation).to.eq("UNKNOWN"); - const requestParams = params.request.params as TransactionRequest[]; - const signTransaction = requestParams[0]; - const signature = await cryptoWallet.signTransaction(signTransaction); - const response = await wallet.approveRequest({ - id, - topic: session.topic, - result: signature, - }); - resolve(response); - }); }), new Promise(async (resolve) => { - const result = await dapp.request({ - topic: session.topic, - request: { - method: "eth_signTransaction", - params: [ - { - from: cryptoWallet.address, - to: cryptoWallet.address, - data: "0x", - nonce: "0x01", - gasPrice: "0x020a7ac094", - gasLimit: "0x5208", - value: "0x00", - }, - ], - }, - chainId: TEST_ETHEREUM_CHAIN, - }); - expect(result).to.be.exist; - expect(result).to.be.a("string"); - resolve(); + try { + await dapp.request({ + topic: session.topic, + request: { + method: "eth_signTransaction", + params: [ + { + from: cryptoWallet.address, + to: cryptoWallet.address, + data: "0x", + nonce: "0x01", + gasPrice: "0x020a7ac094", + gasLimit: "0x5208", + value: "0x00", + }, + ], + }, + chainId: TEST_ETHEREUM_CHAIN, + }); + } catch (e) { + expect(e).to.be.exist; + expect(e).to.toMatchObject(getSdkError("USER_REJECTED")); + resolve(); + } }), ]); // chain was not updated so should stay the same From 3bef2801d8e79220710e3dbbd04cef6b4ac889ca Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Sun, 10 Mar 2024 14:45:20 +0200 Subject: [PATCH 5/9] chore: updates examples --- examples/dapp/package.json | 6 +- examples/dapp/yarn.lock | 74 ++++++++++----------- examples/wallet/package.json | 8 +-- examples/wallet/yarn.lock | 124 ++++++++++------------------------- 4 files changed, 79 insertions(+), 133 deletions(-) diff --git a/examples/dapp/package.json b/examples/dapp/package.json index c7d80a1..faf9a59 100644 --- a/examples/dapp/package.json +++ b/examples/dapp/package.json @@ -30,10 +30,10 @@ "dependencies": { "@ethereumjs/tx": "^3.5.0", "@walletconnect/encoding": "^1.0.1", - "@walletconnect/ethereum-provider": "2.11.0", + "@walletconnect/ethereum-provider": "2.11.2", "@walletconnect/modal": "^2.5.4", - "@walletconnect/types": "2.11.0", - "@walletconnect/utils": "2.11.0", + "@walletconnect/types": "2.11.2", + "@walletconnect/utils": "2.11.2", "axios": "^0.21.1", "blockies-ts": "^1.0.0", "cosmos-wallet": "^1.1.0", diff --git a/examples/dapp/yarn.lock b/examples/dapp/yarn.lock index 2761824..da44759 100644 --- a/examples/dapp/yarn.lock +++ b/examples/dapp/yarn.lock @@ -3055,10 +3055,10 @@ "@typescript-eslint/types" "4.33.0" eslint-visitor-keys "^2.0.0" -"@walletconnect/core@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.0.tgz#3a4e301077b2f858fd916b7a20b5b984d1afce63" - integrity sha512-2Tjp5BCevI7dbmqo/OrCjX4tqgMqwJNQLlQAlphqPfvwlF9+tIu6pGcVbSN3U9zyXzWIZCeleqEaWUeSeET4Ew== +"@walletconnect/core@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.2.tgz#35286be92c645fa461fecc0dfe25de9f076fca8f" + integrity sha512-bB4SiXX8hX3/hyBfVPC5gwZCXCl+OPj+/EDVM71iAO3TDsh78KPbrVAbDnnsbHzZVHlsMohtXX3j5XVsheN3+g== dependencies: "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-provider" "1.0.13" @@ -3071,8 +3071,8 @@ "@walletconnect/relay-auth" "^1.0.4" "@walletconnect/safe-json" "^1.0.2" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" events "^3.3.0" isomorphic-unfetch "3.1.0" lodash.isequal "4.5.0" @@ -3094,20 +3094,20 @@ dependencies: tslib "1.14.1" -"@walletconnect/ethereum-provider@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/ethereum-provider/-/ethereum-provider-2.11.0.tgz#feb90368d8b2608d7d120ac8feeb3e26eac8c709" - integrity sha512-YrTeHVjuSuhlUw7SQ6xBJXDuJ6iAC+RwINm9nVhoKYJSHAy3EVSJZOofMKrnecL0iRMtD29nj57mxAInIBRuZA== +"@walletconnect/ethereum-provider@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/ethereum-provider/-/ethereum-provider-2.11.2.tgz#914f773e37a879bc00cf367437c4e98a826247b1" + integrity sha512-BUDqee0Uy2rCZVkW5Ao3q6Ado/3fePYnFdryVF+YL6bPhj+xQZ5OfKodl+uvs7Rwq++O5wTX2RqOTzpW7+v+Mg== dependencies: "@walletconnect/jsonrpc-http-connection" "^1.0.7" "@walletconnect/jsonrpc-provider" "^1.0.13" "@walletconnect/jsonrpc-types" "^1.0.3" "@walletconnect/jsonrpc-utils" "^1.0.8" "@walletconnect/modal" "^2.6.2" - "@walletconnect/sign-client" "2.11.0" - "@walletconnect/types" "2.11.0" - "@walletconnect/universal-provider" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/sign-client" "2.11.2" + "@walletconnect/types" "2.11.2" + "@walletconnect/universal-provider" "2.11.2" + "@walletconnect/utils" "2.11.2" events "^3.3.0" "@walletconnect/events@^1.0.1": @@ -3292,19 +3292,19 @@ dependencies: tslib "1.14.1" -"@walletconnect/sign-client@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.0.tgz#de10f976cc1b8ab04b7f7c27f6a298e4e083ab25" - integrity sha512-H2ukscibBS+6WrzQWh+WyVBqO5z4F5et12JcwobdwgHnJSlqIoZxqnUYYWNCI5rUR5UKsKWaUyto4AE9N5dw4Q== +"@walletconnect/sign-client@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.2.tgz#855609653855f0d23b0502cdbdcf43402e34c459" + integrity sha512-MfBcuSz2GmMH+P7MrCP46mVE5qhP0ZyWA0FyIH6/WuxQ6G+MgKsGfaITqakpRPsykWOJq8tXMs3XvUPDU413OQ== dependencies: - "@walletconnect/core" "2.11.0" + "@walletconnect/core" "2.11.2" "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "^2.0.1" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" events "^3.3.0" "@walletconnect/time@^1.0.2": @@ -3314,10 +3314,10 @@ dependencies: tslib "1.14.1" -"@walletconnect/types@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.0.tgz#474a009c56faa9ef4063b76ed84415c801dc9f1e" - integrity sha512-AB5b1lrEbCGHxqS2vqfCkIoODieH+ZAUp9rA1O2ftrhnqDJiJK983Df87JhYhECsQUBHHfALphA8ydER0q+9sw== +"@walletconnect/types@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.2.tgz#d0359dd4106fcaa1634241a00428d3ea08d0d3c7" + integrity sha512-p632MFB+lJbip2cvtXPBQslpUdiw1sDtQ5y855bOlAGquay+6fZ4h1DcDePeKQDQM3P77ax2a9aNPZxV6y/h1Q== dependencies: "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" @@ -3326,25 +3326,25 @@ "@walletconnect/logger" "^2.0.1" events "^3.3.0" -"@walletconnect/universal-provider@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/universal-provider/-/universal-provider-2.11.0.tgz#89053c2360b5ce766c213ca4e33bb4ce4976b0be" - integrity sha512-zgJv8jDvIMP4Qse/D9oIRXGdfoNqonsrjPZanQ/CHNe7oXGOBiQND2IIeX+tS0H7uNA0TPvctljCLiIN9nw4eA== +"@walletconnect/universal-provider@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/universal-provider/-/universal-provider-2.11.2.tgz#bec3038f51445d707bbec75f0cb8af0a1f1e04db" + integrity sha512-cNtIn5AVoDxKAJ4PmB8m5adnf5mYQMUamEUPKMVvOPscfGtIMQEh9peKsh2AN5xcRVDbgluC01Id545evFyymw== dependencies: "@walletconnect/jsonrpc-http-connection" "^1.0.7" "@walletconnect/jsonrpc-provider" "1.0.13" "@walletconnect/jsonrpc-types" "^1.0.2" "@walletconnect/jsonrpc-utils" "^1.0.7" "@walletconnect/logger" "^2.0.1" - "@walletconnect/sign-client" "2.11.0" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/sign-client" "2.11.2" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" events "^3.3.0" -"@walletconnect/utils@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.0.tgz#31c95151c823022077883dda61800cdea71879b7" - integrity sha512-hxkHPlTlDQILHfIKXlmzgNJau/YcSBC3XHUSuZuKZbNEw3duFT6h6pm3HT/1+j1a22IG05WDsNBuTCRkwss+BQ== +"@walletconnect/utils@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.2.tgz#dee0f19adf5e38543612cbe9fa4de7ed28eb7e85" + integrity sha512-LyfdmrnZY6dWqlF4eDrx5jpUwsB2bEPjoqR5Z6rXPiHJKUOdJt7az+mNOn5KTSOlRpd1DmozrBrWr+G9fFLYVw== dependencies: "@stablelib/chacha20poly1305" "1.0.1" "@stablelib/hkdf" "1.0.1" @@ -3354,7 +3354,7 @@ "@walletconnect/relay-api" "^1.0.9" "@walletconnect/safe-json" "^1.0.2" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" + "@walletconnect/types" "2.11.2" "@walletconnect/window-getters" "^1.0.1" "@walletconnect/window-metadata" "^1.0.1" detect-browser "5.3.0" diff --git a/examples/wallet/package.json b/examples/wallet/package.json index 24ab680..d548245 100644 --- a/examples/wallet/package.json +++ b/examples/wallet/package.json @@ -13,9 +13,9 @@ "dependencies": { "@json-rpc-tools/utils": "1.7.6", "@nextui-org/react": "1.0.0-beta.12", - "@walletconnect/core": "2.10.3", - "@walletconnect/se-sdk": "1.7.0-rc.0", - "@walletconnect/utils": "2.10.3", + "@walletconnect/core": "2.11.2", + "@walletconnect/se-sdk": "1.7.0-canary-59e3831", + "@walletconnect/utils": "2.11.2", "ethers": "5.7.2", "framer-motion": "9.0.2", "next": "12.2.0", @@ -28,7 +28,7 @@ "devDependencies": { "@types/node": "18.13.0", "@types/react": "18.0.28", - "@walletconnect/types": "2.10.3", + "@walletconnect/types": "2.11.2", "eslint": "8.34.0", "eslint-config-next": "13.1.6", "eslint-config-prettier": "8.6.0", diff --git a/examples/wallet/yarn.lock b/examples/wallet/yarn.lock index 9cbee3a..1dd18be 100644 --- a/examples/wallet/yarn.lock +++ b/examples/wallet/yarn.lock @@ -1898,32 +1898,10 @@ events "^3.3.0" isomorphic-unfetch "^3.1.0" -"@walletconnect/core@2.10.3": - version "2.10.3" - resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.10.3.tgz#413d4acfcf3ca831b2f072a083a830194ebbfd82" - integrity sha512-zvV7Rr48Mftm1+eWr+eTyriV3BFhhY703hGmi2+dA1qMe/5FuIQZs24anBWQapfJuL+CgdGczb/BI9/x3NX7jA== - dependencies: - "@walletconnect/heartbeat" "1.2.1" - "@walletconnect/jsonrpc-provider" "1.0.13" - "@walletconnect/jsonrpc-types" "1.0.3" - "@walletconnect/jsonrpc-utils" "1.0.8" - "@walletconnect/jsonrpc-ws-connection" "1.0.13" - "@walletconnect/keyvaluestorage" "^1.0.2" - "@walletconnect/logger" "^2.0.1" - "@walletconnect/relay-api" "^1.0.9" - "@walletconnect/relay-auth" "^1.0.4" - "@walletconnect/safe-json" "^1.0.2" - "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.10.3" - "@walletconnect/utils" "2.10.3" - events "^3.3.0" - lodash.isequal "4.5.0" - uint8arrays "^3.1.0" - -"@walletconnect/core@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.0.tgz#3a4e301077b2f858fd916b7a20b5b984d1afce63" - integrity sha512-2Tjp5BCevI7dbmqo/OrCjX4tqgMqwJNQLlQAlphqPfvwlF9+tIu6pGcVbSN3U9zyXzWIZCeleqEaWUeSeET4Ew== +"@walletconnect/core@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.2.tgz#35286be92c645fa461fecc0dfe25de9f076fca8f" + integrity sha512-bB4SiXX8hX3/hyBfVPC5gwZCXCl+OPj+/EDVM71iAO3TDsh78KPbrVAbDnnsbHzZVHlsMohtXX3j5XVsheN3+g== dependencies: "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-provider" "1.0.13" @@ -1936,8 +1914,8 @@ "@walletconnect/relay-auth" "^1.0.4" "@walletconnect/safe-json" "^1.0.2" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" events "^3.3.0" isomorphic-unfetch "3.1.0" lodash.isequal "4.5.0" @@ -2088,26 +2066,26 @@ dependencies: tslib "1.14.1" -"@walletconnect/se-sdk@1.7.0-rc.0": - version "1.7.0-rc.0" - resolved "https://registry.yarnpkg.com/@walletconnect/se-sdk/-/se-sdk-1.7.0-rc.0.tgz#599a9748f897fb920b96d032ced5dc853ed20047" - integrity sha512-PSbf9pVFN4EvpTz6M0vKBS5B6p9UKVbyau1NDSE8Pz8F0I8BPHZQaIM2mHJg/ZcCW98hVKNwETU+oT0K7ItCxw== +"@walletconnect/se-sdk@1.7.0-canary-59e3831": + version "1.7.0-canary-59e3831" + resolved "https://registry.yarnpkg.com/@walletconnect/se-sdk/-/se-sdk-1.7.0-canary-59e3831.tgz#805ec7ef15d3660214ccaadc93bcf7c8c0e65f6f" + integrity sha512-xE942ayz93hG5/a6eRsVsfSTdeoqUXrHLHIhBkBNdWLU7AEmwe+8cVV7mRhKxWJRz5AmQXqFCfNwqQR9/m0Mdg== dependencies: - "@walletconnect/web3wallet" "1.10.0" + "@walletconnect/web3wallet" "1.10.2" -"@walletconnect/sign-client@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.0.tgz#de10f976cc1b8ab04b7f7c27f6a298e4e083ab25" - integrity sha512-H2ukscibBS+6WrzQWh+WyVBqO5z4F5et12JcwobdwgHnJSlqIoZxqnUYYWNCI5rUR5UKsKWaUyto4AE9N5dw4Q== +"@walletconnect/sign-client@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.2.tgz#855609653855f0d23b0502cdbdcf43402e34c459" + integrity sha512-MfBcuSz2GmMH+P7MrCP46mVE5qhP0ZyWA0FyIH6/WuxQ6G+MgKsGfaITqakpRPsykWOJq8tXMs3XvUPDU413OQ== dependencies: - "@walletconnect/core" "2.11.0" + "@walletconnect/core" "2.11.2" "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "^2.0.1" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" events "^3.3.0" "@walletconnect/time@^1.0.2": @@ -2129,22 +2107,10 @@ "@walletconnect/logger" "^2.0.1" events "^3.3.0" -"@walletconnect/types@2.10.3": - version "2.10.3" - resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.10.3.tgz#e32adaf6ca921f4c08e1331fc5f919b5baad8120" - integrity sha512-HcLR4JKTQyVoconQ8CqxtPrIVYHMQwZtvBq5RD0InuhxChabu2GsxtSfmz+M7ShzKWItohZx1EQJKYZKYw9ekA== - dependencies: - "@walletconnect/events" "^1.0.1" - "@walletconnect/heartbeat" "1.2.1" - "@walletconnect/jsonrpc-types" "1.0.3" - "@walletconnect/keyvaluestorage" "^1.0.2" - "@walletconnect/logger" "^2.0.1" - events "^3.3.0" - -"@walletconnect/types@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.0.tgz#474a009c56faa9ef4063b76ed84415c801dc9f1e" - integrity sha512-AB5b1lrEbCGHxqS2vqfCkIoODieH+ZAUp9rA1O2ftrhnqDJiJK983Df87JhYhECsQUBHHfALphA8ydER0q+9sw== +"@walletconnect/types@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.2.tgz#d0359dd4106fcaa1634241a00428d3ea08d0d3c7" + integrity sha512-p632MFB+lJbip2cvtXPBQslpUdiw1sDtQ5y855bOlAGquay+6fZ4h1DcDePeKQDQM3P77ax2a9aNPZxV6y/h1Q== dependencies: "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" @@ -2173,30 +2139,10 @@ query-string "7.1.3" uint8arrays "^3.1.0" -"@walletconnect/utils@2.10.3": - version "2.10.3" - resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.10.3.tgz#56fb9a6ab96a3c85f952205dc5042f1c0f1e9f6c" - integrity sha512-9FTujY4t+SrENgvyT84TFsO1iFvix2dWH5C9PmJ3/LMrkYytjszJVMPY5bDG73RBwph9wbeYzPgkGvid2RP63A== - dependencies: - "@stablelib/chacha20poly1305" "1.0.1" - "@stablelib/hkdf" "1.0.1" - "@stablelib/random" "^1.0.2" - "@stablelib/sha256" "1.0.1" - "@stablelib/x25519" "^1.0.3" - "@walletconnect/relay-api" "^1.0.9" - "@walletconnect/safe-json" "^1.0.2" - "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.10.3" - "@walletconnect/window-getters" "^1.0.1" - "@walletconnect/window-metadata" "^1.0.1" - detect-browser "5.3.0" - query-string "7.1.3" - uint8arrays "^3.1.0" - -"@walletconnect/utils@2.11.0": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.0.tgz#31c95151c823022077883dda61800cdea71879b7" - integrity sha512-hxkHPlTlDQILHfIKXlmzgNJau/YcSBC3XHUSuZuKZbNEw3duFT6h6pm3HT/1+j1a22IG05WDsNBuTCRkwss+BQ== +"@walletconnect/utils@2.11.2": + version "2.11.2" + resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.2.tgz#dee0f19adf5e38543612cbe9fa4de7ed28eb7e85" + integrity sha512-LyfdmrnZY6dWqlF4eDrx5jpUwsB2bEPjoqR5Z6rXPiHJKUOdJt7az+mNOn5KTSOlRpd1DmozrBrWr+G9fFLYVw== dependencies: "@stablelib/chacha20poly1305" "1.0.1" "@stablelib/hkdf" "1.0.1" @@ -2206,26 +2152,26 @@ "@walletconnect/relay-api" "^1.0.9" "@walletconnect/safe-json" "^1.0.2" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.0" + "@walletconnect/types" "2.11.2" "@walletconnect/window-getters" "^1.0.1" "@walletconnect/window-metadata" "^1.0.1" detect-browser "5.3.0" query-string "7.1.3" uint8arrays "^3.1.0" -"@walletconnect/web3wallet@1.10.0": - version "1.10.0" - resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.0.tgz#5a7f181bbea213e8fb5961900a0069e58da36d18" - integrity sha512-JyaYdnBKL1hVpsE5hpjZhohpX1Ak2mwai3GYr8nI1FfK8Z3IPIh+4ImeDMnEao1cQFoItQNompp5y5C7WlI69A== +"@walletconnect/web3wallet@1.10.2": + version "1.10.2" + resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.2.tgz#5887642773e6e1b88d1bfb159a00ec45b31f762a" + integrity sha512-FbWsJwhihppl6poJ0+0WCkjXZDVdb11KJiS/AJt+qyNheIKQ7z6NfCnCnnKPBEpNNoUPclcFo4b/BmdFo2YlMw== dependencies: "@walletconnect/auth-client" "2.1.2" - "@walletconnect/core" "2.11.0" + "@walletconnect/core" "2.11.2" "@walletconnect/jsonrpc-provider" "1.0.13" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "2.0.1" - "@walletconnect/sign-client" "2.11.0" - "@walletconnect/types" "2.11.0" - "@walletconnect/utils" "2.11.0" + "@walletconnect/sign-client" "2.11.2" + "@walletconnect/types" "2.11.2" + "@walletconnect/utils" "2.11.2" "@walletconnect/window-getters@^1.0.1": version "1.0.1" From 70d48e1c1975f6ecb0521fb881e2f075a82cf156 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Mon, 11 Mar 2024 09:43:44 +0200 Subject: [PATCH 6/9] fix: updates example's wallet active `chainId` --- examples/wallet/src/views/SwitchChainModal.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/wallet/src/views/SwitchChainModal.tsx b/examples/wallet/src/views/SwitchChainModal.tsx index 27bd6f9..64a42ad 100644 --- a/examples/wallet/src/views/SwitchChainModal.tsx +++ b/examples/wallet/src/views/SwitchChainModal.tsx @@ -33,6 +33,7 @@ export default function SwitchChainModal() { id: requestEvent.id, result: {}, }); + SettingsStore.setActiveChainId(parseInt(hexChain)); await web3wallet.updateSession({ topic, chainId: parseInt(hexChain), From c312e421e54321229dcdec09e49b5c1a6458e8b9 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 20 Mar 2024 14:57:41 +0200 Subject: [PATCH 7/9] chore: updates canary --- examples/wallet/package.json | 2 +- examples/wallet/yarn.lock | 8 ++++---- src/controllers/engine.ts | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/wallet/package.json b/examples/wallet/package.json index d548245..ca54f28 100644 --- a/examples/wallet/package.json +++ b/examples/wallet/package.json @@ -14,7 +14,7 @@ "@json-rpc-tools/utils": "1.7.6", "@nextui-org/react": "1.0.0-beta.12", "@walletconnect/core": "2.11.2", - "@walletconnect/se-sdk": "1.7.0-canary-59e3831", + "@walletconnect/se-sdk": "1.7.0-canary-82cf156-1", "@walletconnect/utils": "2.11.2", "ethers": "5.7.2", "framer-motion": "9.0.2", diff --git a/examples/wallet/yarn.lock b/examples/wallet/yarn.lock index 1dd18be..f708480 100644 --- a/examples/wallet/yarn.lock +++ b/examples/wallet/yarn.lock @@ -2066,10 +2066,10 @@ dependencies: tslib "1.14.1" -"@walletconnect/se-sdk@1.7.0-canary-59e3831": - version "1.7.0-canary-59e3831" - resolved "https://registry.yarnpkg.com/@walletconnect/se-sdk/-/se-sdk-1.7.0-canary-59e3831.tgz#805ec7ef15d3660214ccaadc93bcf7c8c0e65f6f" - integrity sha512-xE942ayz93hG5/a6eRsVsfSTdeoqUXrHLHIhBkBNdWLU7AEmwe+8cVV7mRhKxWJRz5AmQXqFCfNwqQR9/m0Mdg== +"@walletconnect/se-sdk@1.7.0-canary-82cf156-1": + version "1.7.0-canary-82cf156-1" + resolved "https://registry.yarnpkg.com/@walletconnect/se-sdk/-/se-sdk-1.7.0-canary-82cf156-1.tgz#e8b52b29d1f32a55e9d21bf13ff6441cc9b771ea" + integrity sha512-3DMq5hUdIh68u9KeUEenDwkTDm4Kif2B2qscNlqqo0bp/6bM0tSlwM6XwtOgty3VOysUHhhSE4G+lJafs1TagA== dependencies: "@walletconnect/web3wallet" "1.10.2" diff --git a/src/controllers/engine.ts b/src/controllers/engine.ts index 3394ac0..210c526 100644 --- a/src/controllers/engine.ts +++ b/src/controllers/engine.ts @@ -101,6 +101,10 @@ export class Engine extends ISingleEthereumEngine { public updateSession: ISingleEthereumEngine["updateSession"] = async (params) => { const { topic, chainId, accounts } = params; + if (chainId < 1) { + // eslint-disable-next-line no-console + return console.error("se-sdk, updateSession Invalid chainId", chainId); + } const session = this.web3wallet.engine.signClient.session.get(topic); const formattedChain = prefixChainWithNamespace(chainId); const formattedAccounts = formatAccounts(accounts, chainId); From 099f303b5155e63bab00ed404c0237b443f829e6 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 20 Mar 2024 15:00:03 +0200 Subject: [PATCH 8/9] chore: updates w3wallet version --- package.json | 4 ++-- yarn.lock | 60 ++++++++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 47a6862..1394b7b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@walletconnect/se-sdk", "description": "Single-Ethreum-SDK for WalletConnect Protocol", "private": false, - "version": "1.7.0", + "version": "1.7.1", "author": "WalletConnect, Inc. ", "homepage": "https://github.com/walletconnect/walletconnect-monorepo/", "license": "Apache-2.0", @@ -33,7 +33,7 @@ "install:all": "yarn && cd ./examples/dapp && yarn && cd ./../wallet && yarn" }, "dependencies": { - "@walletconnect/web3wallet": "1.10.2" + "@walletconnect/web3wallet": "1.10.3" }, "devDependencies": { "@ethersproject/wallet": "^5.7.0", diff --git a/yarn.lock b/yarn.lock index 58e6344..83c5eed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -918,10 +918,10 @@ events "^3.3.0" isomorphic-unfetch "^3.1.0" -"@walletconnect/core@2.11.2": - version "2.11.2" - resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.2.tgz#35286be92c645fa461fecc0dfe25de9f076fca8f" - integrity sha512-bB4SiXX8hX3/hyBfVPC5gwZCXCl+OPj+/EDVM71iAO3TDsh78KPbrVAbDnnsbHzZVHlsMohtXX3j5XVsheN3+g== +"@walletconnect/core@2.11.3": + version "2.11.3" + resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.3.tgz#c81855722cb9afd411f91f5345c7874f48bade0b" + integrity sha512-/9m4EqiggFUwkQDv5PDWbcTI+yCVnBd/iYW5iIHEkivg2/mnBr2bQz2r/vtPjp19r/ZK62Dx0+UN3U+BWP8ulQ== dependencies: "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-provider" "1.0.13" @@ -934,8 +934,8 @@ "@walletconnect/relay-auth" "^1.0.4" "@walletconnect/safe-json" "^1.0.2" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.2" - "@walletconnect/utils" "2.11.2" + "@walletconnect/types" "2.11.3" + "@walletconnect/utils" "2.11.3" events "^3.3.0" isomorphic-unfetch "3.1.0" lodash.isequal "4.5.0" @@ -1086,19 +1086,19 @@ dependencies: tslib "1.14.1" -"@walletconnect/sign-client@2.11.2": - version "2.11.2" - resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.2.tgz#855609653855f0d23b0502cdbdcf43402e34c459" - integrity sha512-MfBcuSz2GmMH+P7MrCP46mVE5qhP0ZyWA0FyIH6/WuxQ6G+MgKsGfaITqakpRPsykWOJq8tXMs3XvUPDU413OQ== +"@walletconnect/sign-client@2.11.3": + version "2.11.3" + resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.3.tgz#3ea7b3acf92ee31cc42b45d42e66c44b4720b28b" + integrity sha512-JVjLTxN/3NjMXv5zalSGKuSYLRyU2yX6AWEdq17cInlrwODpbWZr6PS1uxMWdH4r90DXBLhdtwDbEq/pfd0BPg== dependencies: - "@walletconnect/core" "2.11.2" + "@walletconnect/core" "2.11.3" "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "^2.0.1" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.2" - "@walletconnect/utils" "2.11.2" + "@walletconnect/types" "2.11.3" + "@walletconnect/utils" "2.11.3" events "^3.3.0" "@walletconnect/time@^1.0.2": @@ -1120,10 +1120,10 @@ "@walletconnect/logger" "^2.0.1" events "^3.3.0" -"@walletconnect/types@2.11.2": - version "2.11.2" - resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.2.tgz#d0359dd4106fcaa1634241a00428d3ea08d0d3c7" - integrity sha512-p632MFB+lJbip2cvtXPBQslpUdiw1sDtQ5y855bOlAGquay+6fZ4h1DcDePeKQDQM3P77ax2a9aNPZxV6y/h1Q== +"@walletconnect/types@2.11.3": + version "2.11.3" + resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.3.tgz#8ce43cb77e8fd9d5269847cdd73bcfa7cce7dd1a" + integrity sha512-JY4wA9MVosDW9dcJMTpnwliste0aJGJ1X6Q4ulLsQsgWRSEBRkLila0oUT01TDBW9Yq8uUp7uFOUTaKx6KWVAg== dependencies: "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" @@ -1152,10 +1152,10 @@ query-string "7.1.3" uint8arrays "^3.1.0" -"@walletconnect/utils@2.11.2": - version "2.11.2" - resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.2.tgz#dee0f19adf5e38543612cbe9fa4de7ed28eb7e85" - integrity sha512-LyfdmrnZY6dWqlF4eDrx5jpUwsB2bEPjoqR5Z6rXPiHJKUOdJt7az+mNOn5KTSOlRpd1DmozrBrWr+G9fFLYVw== +"@walletconnect/utils@2.11.3": + version "2.11.3" + resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.3.tgz#3731809b54902655cf202e0bf0e8f268780e8b54" + integrity sha512-jsdNkrl/IcTkzWFn0S2d0urzBXg6RxVJtUYRsUx3qI3wzOGiABP9ui3yiZ3SgZOv9aRe62PaNp1qpbYZ+zPb8Q== dependencies: "@stablelib/chacha20poly1305" "1.0.1" "@stablelib/hkdf" "1.0.1" @@ -1165,26 +1165,26 @@ "@walletconnect/relay-api" "^1.0.9" "@walletconnect/safe-json" "^1.0.2" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.2" + "@walletconnect/types" "2.11.3" "@walletconnect/window-getters" "^1.0.1" "@walletconnect/window-metadata" "^1.0.1" detect-browser "5.3.0" query-string "7.1.3" uint8arrays "^3.1.0" -"@walletconnect/web3wallet@1.10.2": - version "1.10.2" - resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.2.tgz#5887642773e6e1b88d1bfb159a00ec45b31f762a" - integrity sha512-FbWsJwhihppl6poJ0+0WCkjXZDVdb11KJiS/AJt+qyNheIKQ7z6NfCnCnnKPBEpNNoUPclcFo4b/BmdFo2YlMw== +"@walletconnect/web3wallet@1.10.3": + version "1.10.3" + resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.3.tgz#8195308757bd298ccc9caa6e3fe9f4ff82b94607" + integrity sha512-1Dr2P8KIDCqEWZ+s4coKGJz/+pj87ogFs+icPDXPu9QpzTgY5Y1WSzuAHaqoY5gTlL7WS58YP49s0E7iacUz4g== dependencies: "@walletconnect/auth-client" "2.1.2" - "@walletconnect/core" "2.11.2" + "@walletconnect/core" "2.11.3" "@walletconnect/jsonrpc-provider" "1.0.13" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "2.0.1" - "@walletconnect/sign-client" "2.11.2" - "@walletconnect/types" "2.11.2" - "@walletconnect/utils" "2.11.2" + "@walletconnect/sign-client" "2.11.3" + "@walletconnect/types" "2.11.3" + "@walletconnect/utils" "2.11.3" "@walletconnect/window-getters@^1.0.1": version "1.0.1" From bdecf43e18098f9332484dcc4957e482ef5cf347 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Mon, 25 Mar 2024 12:58:55 +0200 Subject: [PATCH 9/9] refactor: reverts replacing chains on update. --- examples/wallet/package.json | 2 +- examples/wallet/yarn.lock | 95 ++++++++++++++++++++++++++++-------- src/controllers/engine.ts | 36 ++++++++------ test/shared/values.ts | 2 +- test/sign.spec.ts | 12 ++++- 5 files changed, 107 insertions(+), 40 deletions(-) diff --git a/examples/wallet/package.json b/examples/wallet/package.json index ca54f28..ea86e88 100644 --- a/examples/wallet/package.json +++ b/examples/wallet/package.json @@ -14,7 +14,7 @@ "@json-rpc-tools/utils": "1.7.6", "@nextui-org/react": "1.0.0-beta.12", "@walletconnect/core": "2.11.2", - "@walletconnect/se-sdk": "1.7.0-canary-82cf156-1", + "@walletconnect/se-sdk": "1.7.1-canary.1", "@walletconnect/utils": "2.11.2", "ethers": "5.7.2", "framer-motion": "9.0.2", diff --git a/examples/wallet/yarn.lock b/examples/wallet/yarn.lock index f708480..1370b0e 100644 --- a/examples/wallet/yarn.lock +++ b/examples/wallet/yarn.lock @@ -1921,6 +1921,29 @@ lodash.isequal "4.5.0" uint8arrays "^3.1.0" +"@walletconnect/core@2.11.3": + version "2.11.3" + resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.3.tgz#c81855722cb9afd411f91f5345c7874f48bade0b" + integrity sha512-/9m4EqiggFUwkQDv5PDWbcTI+yCVnBd/iYW5iIHEkivg2/mnBr2bQz2r/vtPjp19r/ZK62Dx0+UN3U+BWP8ulQ== + dependencies: + "@walletconnect/heartbeat" "1.2.1" + "@walletconnect/jsonrpc-provider" "1.0.13" + "@walletconnect/jsonrpc-types" "1.0.3" + "@walletconnect/jsonrpc-utils" "1.0.8" + "@walletconnect/jsonrpc-ws-connection" "1.0.14" + "@walletconnect/keyvaluestorage" "^1.1.1" + "@walletconnect/logger" "^2.0.1" + "@walletconnect/relay-api" "^1.0.9" + "@walletconnect/relay-auth" "^1.0.4" + "@walletconnect/safe-json" "^1.0.2" + "@walletconnect/time" "^1.0.2" + "@walletconnect/types" "2.11.3" + "@walletconnect/utils" "2.11.3" + events "^3.3.0" + isomorphic-unfetch "3.1.0" + lodash.isequal "4.5.0" + uint8arrays "^3.1.0" + "@walletconnect/core@^2.10.1": version "2.10.1" resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.10.1.tgz#d1fb442bd77424666bacdb0f5a07f7708fb3d984" @@ -2066,26 +2089,26 @@ dependencies: tslib "1.14.1" -"@walletconnect/se-sdk@1.7.0-canary-82cf156-1": - version "1.7.0-canary-82cf156-1" - resolved "https://registry.yarnpkg.com/@walletconnect/se-sdk/-/se-sdk-1.7.0-canary-82cf156-1.tgz#e8b52b29d1f32a55e9d21bf13ff6441cc9b771ea" - integrity sha512-3DMq5hUdIh68u9KeUEenDwkTDm4Kif2B2qscNlqqo0bp/6bM0tSlwM6XwtOgty3VOysUHhhSE4G+lJafs1TagA== +"@walletconnect/se-sdk@1.7.1-canary.1": + version "1.7.1-canary.1" + resolved "https://registry.yarnpkg.com/@walletconnect/se-sdk/-/se-sdk-1.7.1-canary.1.tgz#9b50fd5c36bc953e5de5bbf249b15112475791f3" + integrity sha512-FZx1a66VW7U07iUq0SwJH/dyEnX88GQIUHl1ceN5wSfL2HDAvJEjqHVWm4cLvozTLSA3Fd2ZU9iG3q7FQSmOwA== dependencies: - "@walletconnect/web3wallet" "1.10.2" + "@walletconnect/web3wallet" "1.10.3" -"@walletconnect/sign-client@2.11.2": - version "2.11.2" - resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.2.tgz#855609653855f0d23b0502cdbdcf43402e34c459" - integrity sha512-MfBcuSz2GmMH+P7MrCP46mVE5qhP0ZyWA0FyIH6/WuxQ6G+MgKsGfaITqakpRPsykWOJq8tXMs3XvUPDU413OQ== +"@walletconnect/sign-client@2.11.3": + version "2.11.3" + resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.3.tgz#3ea7b3acf92ee31cc42b45d42e66c44b4720b28b" + integrity sha512-JVjLTxN/3NjMXv5zalSGKuSYLRyU2yX6AWEdq17cInlrwODpbWZr6PS1uxMWdH4r90DXBLhdtwDbEq/pfd0BPg== dependencies: - "@walletconnect/core" "2.11.2" + "@walletconnect/core" "2.11.3" "@walletconnect/events" "^1.0.1" "@walletconnect/heartbeat" "1.2.1" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "^2.0.1" "@walletconnect/time" "^1.0.2" - "@walletconnect/types" "2.11.2" - "@walletconnect/utils" "2.11.2" + "@walletconnect/types" "2.11.3" + "@walletconnect/utils" "2.11.3" events "^3.3.0" "@walletconnect/time@^1.0.2": @@ -2119,6 +2142,18 @@ "@walletconnect/logger" "^2.0.1" events "^3.3.0" +"@walletconnect/types@2.11.3": + version "2.11.3" + resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.3.tgz#8ce43cb77e8fd9d5269847cdd73bcfa7cce7dd1a" + integrity sha512-JY4wA9MVosDW9dcJMTpnwliste0aJGJ1X6Q4ulLsQsgWRSEBRkLila0oUT01TDBW9Yq8uUp7uFOUTaKx6KWVAg== + dependencies: + "@walletconnect/events" "^1.0.1" + "@walletconnect/heartbeat" "1.2.1" + "@walletconnect/jsonrpc-types" "1.0.3" + "@walletconnect/keyvaluestorage" "^1.1.1" + "@walletconnect/logger" "^2.0.1" + events "^3.3.0" + "@walletconnect/utils@2.10.1", "@walletconnect/utils@^2.10.1": version "2.10.1" resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.10.1.tgz#65b37c9800eb0e80a08385b6987471fb46e1e22e" @@ -2159,19 +2194,39 @@ query-string "7.1.3" uint8arrays "^3.1.0" -"@walletconnect/web3wallet@1.10.2": - version "1.10.2" - resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.2.tgz#5887642773e6e1b88d1bfb159a00ec45b31f762a" - integrity sha512-FbWsJwhihppl6poJ0+0WCkjXZDVdb11KJiS/AJt+qyNheIKQ7z6NfCnCnnKPBEpNNoUPclcFo4b/BmdFo2YlMw== +"@walletconnect/utils@2.11.3": + version "2.11.3" + resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.3.tgz#3731809b54902655cf202e0bf0e8f268780e8b54" + integrity sha512-jsdNkrl/IcTkzWFn0S2d0urzBXg6RxVJtUYRsUx3qI3wzOGiABP9ui3yiZ3SgZOv9aRe62PaNp1qpbYZ+zPb8Q== + dependencies: + "@stablelib/chacha20poly1305" "1.0.1" + "@stablelib/hkdf" "1.0.1" + "@stablelib/random" "^1.0.2" + "@stablelib/sha256" "1.0.1" + "@stablelib/x25519" "^1.0.3" + "@walletconnect/relay-api" "^1.0.9" + "@walletconnect/safe-json" "^1.0.2" + "@walletconnect/time" "^1.0.2" + "@walletconnect/types" "2.11.3" + "@walletconnect/window-getters" "^1.0.1" + "@walletconnect/window-metadata" "^1.0.1" + detect-browser "5.3.0" + query-string "7.1.3" + uint8arrays "^3.1.0" + +"@walletconnect/web3wallet@1.10.3": + version "1.10.3" + resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.3.tgz#8195308757bd298ccc9caa6e3fe9f4ff82b94607" + integrity sha512-1Dr2P8KIDCqEWZ+s4coKGJz/+pj87ogFs+icPDXPu9QpzTgY5Y1WSzuAHaqoY5gTlL7WS58YP49s0E7iacUz4g== dependencies: "@walletconnect/auth-client" "2.1.2" - "@walletconnect/core" "2.11.2" + "@walletconnect/core" "2.11.3" "@walletconnect/jsonrpc-provider" "1.0.13" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "2.0.1" - "@walletconnect/sign-client" "2.11.2" - "@walletconnect/types" "2.11.2" - "@walletconnect/utils" "2.11.2" + "@walletconnect/sign-client" "2.11.3" + "@walletconnect/types" "2.11.3" + "@walletconnect/utils" "2.11.3" "@walletconnect/window-getters@^1.0.1": version "1.0.1" diff --git a/src/controllers/engine.ts b/src/controllers/engine.ts index 210c526..032e50f 100644 --- a/src/controllers/engine.ts +++ b/src/controllers/engine.ts @@ -55,7 +55,12 @@ export class Engine extends ISingleEthereumEngine { const parsed = parseChain(chain); return parseInt(parsed); }); - const approvedChains = [...new Set([chainId, ...requiredChains])]; + const optionalChains = (normalizedOptional[EVM_IDENTIFIER]?.chains || []).map((chain) => { + const parsed = parseChain(chain); + return parseInt(parsed); + }); + + const approvedChains = [...new Set([chainId, ...requiredChains, ...optionalChains])]; const approveParams = { id, namespaces: { @@ -111,16 +116,12 @@ export class Engine extends ISingleEthereumEngine { const namespaces = session.namespaces[EVM_IDENTIFIER]; let shouldUpdateSession = false; if (!chainAlreadyInSession(session, chainId)) { - const requiredChains = session.requiredNamespaces?.[EVM_IDENTIFIER]?.chains || []; - namespaces.chains = [formattedChain, ...requiredChains]; + namespaces?.chains?.push(formattedChain); shouldUpdateSession = true; } if (!accountsAlreadyInSession(session, formattedAccounts)) { - namespaces.accounts = - namespaces.chains - ?.map((chain) => formatAccounts(accounts, parseInt(parseChain(chain)))) - .flat() || []; + namespaces.accounts = namespaces.accounts.concat(formattedAccounts); shouldUpdateSession = true; } @@ -149,15 +150,18 @@ export class Engine extends ISingleEthereumEngine { await this.changeChain(topic, chainId); this.chainId = chainId; } - - await this.web3wallet.emitSessionEvent({ - topic, - event: { - name: "accountsChanged", - data: formattedAccounts, - }, - chainId: formattedChain, - }); + try { + await this.web3wallet.emitSessionEvent({ + topic, + event: { + name: "accountsChanged", + data: formattedAccounts, + }, + chainId: formattedChain, + }); + } catch (e) { + this.client.logger.warn(e); + } }; public approveRequest: ISingleEthereumEngine["approveRequest"] = async (params) => { diff --git a/test/shared/values.ts b/test/shared/values.ts index 8113892..4408ac5 100644 --- a/test/shared/values.ts +++ b/test/shared/values.ts @@ -34,7 +34,7 @@ export const TEST_NAMESPACES = { export const TEST_UPDATED_NAMESPACES = { eip155: { methods: TEST_METHODS.concat(TEST_OPTIONAL_METHODS), - accounts: [TEST_GOERLI_ACCOUNT, TEST_ETHEREUM_ACCOUNT], + accounts: [TEST_ETHEREUM_ACCOUNT, TEST_GOERLI_ACCOUNT], events: TEST_EVENTS, }, }; diff --git a/test/sign.spec.ts b/test/sign.spec.ts index 132803c..048f080 100644 --- a/test/sign.spec.ts +++ b/test/sign.spec.ts @@ -188,7 +188,15 @@ describe("Sign Integration", () => { new Promise((resolve) => { dapp.events.on("session_update", (session) => { const { params } = session; - expect(params.namespaces).to.toMatchObject(TEST_UPDATED_NAMESPACES); + expect(params.namespaces.eip155.accounts).to.toMatchObject( + TEST_UPDATED_NAMESPACES.eip155.accounts, + ); + expect(params.namespaces.eip155.methods).to.toMatchObject( + TEST_UPDATED_NAMESPACES.eip155.methods, + ); + expect(params.namespaces.eip155.events).to.toMatchObject( + TEST_UPDATED_NAMESPACES.eip155.events, + ); resolve(session); }); }), @@ -261,7 +269,7 @@ describe("Sign Integration", () => { ]); }); - it("should replace approved chainId on update", async () => { + it.skip("should replace approved chainId on update", async () => { dapp = await SignClient.init({ ...TEST_CORE_OPTIONS, name: "Dapp",