From a8a88467c6764567d0edc843906445d0f609b5b4 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 24 May 2023 17:57:11 +0300 Subject: [PATCH 1/3] chore: updates deps --- package.json | 2 +- yarn.lock | 86 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 71 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index bc2b9b9..ff43f49 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.7.4" + "@walletconnect/web3wallet": "1.7.5" }, "devDependencies": { "@ethersproject/wallet": "^5.7.0", diff --git a/yarn.lock b/yarn.lock index 9b462a5..e67d652 100644 --- a/yarn.lock +++ b/yarn.lock @@ -821,7 +821,29 @@ events "^3.3.0" isomorphic-unfetch "^3.1.0" -"@walletconnect/core@2.7.6", "@walletconnect/core@^2.7.2": +"@walletconnect/core@2.7.7": + version "2.7.7" + resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.7.7.tgz#49ddaa9d8aff365cd347b951d9b4c1c39a949e83" + integrity sha512-/Tmrjx9XDG8qylsUFU2fWvMoxlDwW+zzUcCgTaebMAmssCZ8NSknbBdjAdAKiey1TaLEgFkaCxXgXfioinWNYg== + 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.11" + "@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.7.7" + "@walletconnect/utils" "2.7.7" + events "^3.3.0" + lodash.isequal "4.5.0" + uint8arrays "^3.1.0" + +"@walletconnect/core@^2.7.2": version "2.7.6" resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.7.6.tgz#d1773e6f06ec077a25504e3944c3c9ba82fa1c9e" integrity sha512-EPzKfH9EpOVmJhfedddpNjG6Lz0zWnAZSBvXSeuBlOyD3Aayiky3HuiDcpK+YyRzyWEsh2kWMvvTZ6v0uFAApQ== @@ -980,19 +1002,19 @@ dependencies: tslib "1.14.1" -"@walletconnect/sign-client@2.7.6": - version "2.7.6" - resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.7.6.tgz#c6fda665043c5fbcc6085f8b5c7a666bb1fdc233" - integrity sha512-u3wVjK1XAhj1ZVzAs+SP5VYEP2FWYH/y6tnaLHLqZcsoZ/a2sGCnJlK9y7HA6q3jLBt6lVBkT1qSU4pmBY4xlw== +"@walletconnect/sign-client@2.7.7": + version "2.7.7" + resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.7.7.tgz#a2be064eaff37ab036919bd33f1cf9ddf4681fdd" + integrity sha512-lTyF8ZEp+HwPNBW/Fw5iWnMm9O5tC1qwf5YfhNczZ7+q6+UUopOoRrsAvwqftJIkgKmfC8lHT52G/XM2JGVjbQ== dependencies: - "@walletconnect/core" "2.7.6" + "@walletconnect/core" "2.7.7" "@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.7.6" - "@walletconnect/utils" "2.7.6" + "@walletconnect/types" "2.7.7" + "@walletconnect/utils" "2.7.7" events "^3.3.0" "@walletconnect/time@^1.0.2": @@ -1014,6 +1036,18 @@ "@walletconnect/logger" "^2.0.1" events "^3.3.0" +"@walletconnect/types@2.7.7": + version "2.7.7" + resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.7.7.tgz#c02831a17b6162d8594c45e3cc4668015e022f51" + integrity sha512-Z4Y+BKPX7X1UBCf7QV35mVy2QU9CS+5G+EthCaJwpieirZNHamHEwNXUjuUUb3PrYOLwlfRYUT5edeFW9wvoeQ== + 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/utils@2.7.6", "@walletconnect/utils@^2.7.2": version "2.7.6" resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.7.6.tgz#42ff9d7bb3c1874aa85d480181c6a7aafc34c90f" @@ -1034,19 +1068,39 @@ query-string "7.1.3" uint8arrays "^3.1.0" -"@walletconnect/web3wallet@1.7.4": - version "1.7.4" - resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.7.4.tgz#708fbf8bd0ce106c3497c5120d783a62ea79ba3c" - integrity sha512-HAjCt2lbkNG+48iVYZ/o7fBcsol5roh1oCHgBr7h61ohAiQ5qV6Dgr/j2kWb+f1qxNOOwxfdXgIKuTkOtP0OfA== +"@walletconnect/utils@2.7.7": + version "2.7.7" + resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.7.7.tgz#e2d8732f8ac3ffbc1de13e923891b256eb3bbefb" + integrity sha512-ozh9gvRAdXkiu+6nOAkoDCokDVPXK/tNATrrYuOhhR+EmGDjlZU2d27HT+HiGREdza0b1HdZN4XneGm0gERV5w== + 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.7.7" + "@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.7.5": + version "1.7.5" + resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.7.5.tgz#cb624f4be5ff2ff17cab23de93f588611bd6452f" + integrity sha512-9fdfbPfczyUdcYK2O353uRtOCEVtlM8zLMPPVUHZEzVuJ1M4DHLRj1K5SDH62UQt1WA3ue8U8s4aEH5RKle6ww== dependencies: "@walletconnect/auth-client" "2.1.0" - "@walletconnect/core" "2.7.6" + "@walletconnect/core" "2.7.7" "@walletconnect/jsonrpc-provider" "1.0.13" "@walletconnect/jsonrpc-utils" "1.0.8" "@walletconnect/logger" "2.0.1" - "@walletconnect/sign-client" "2.7.6" - "@walletconnect/types" "2.7.6" - "@walletconnect/utils" "2.7.6" + "@walletconnect/sign-client" "2.7.7" + "@walletconnect/types" "2.7.7" + "@walletconnect/utils" "2.7.7" "@walletconnect/window-getters@^1.0.1": version "1.0.1" From 6b37095e7bc993db13be0e3a1cacc8300e2603a6 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 24 May 2023 17:57:51 +0300 Subject: [PATCH 2/3] feat: emits `session_proposal_error` event when auto validation fails --- src/controllers/engine.ts | 8 ++++++-- src/types/client.ts | 13 ++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/controllers/engine.ts b/src/controllers/engine.ts index 46ab182..401bca0 100644 --- a/src/controllers/engine.ts +++ b/src/controllers/engine.ts @@ -215,9 +215,11 @@ export class Engine extends ISingleEthereumEngine { validateProposalNamespaces(proposal); } catch (e) { this.client.logger.error(e); + const error = getSdkError("UNSUPPORTED_NAMESPACE_KEY"); + this.client.events.emit("session_proposal_error", error); return this.rejectSession({ id: event.id, - error: getSdkError("UNSUPPORTED_NAMESPACE_KEY"), + error, }); } @@ -225,9 +227,11 @@ export class Engine extends ISingleEthereumEngine { validateProposalChains(proposal); } catch (e) { this.client.logger.error(e); + const error = getSdkError("UNSUPPORTED_CHAINS"); + this.client.events.emit("session_proposal_error", error); return this.rejectSession({ id: event.id, - error: getSdkError("UNSUPPORTED_CHAINS"), + error, }); } return this.client.events.emit("session_proposal", { diff --git a/src/types/client.ts b/src/types/client.ts index fe94f90..c8adf0b 100644 --- a/src/types/client.ts +++ b/src/types/client.ts @@ -6,7 +6,12 @@ import { AuthEngineTypes } from "@walletconnect/auth-client"; import { Web3WalletTypes } from "@walletconnect/web3wallet"; export declare namespace SingleEthereumTypes { - type Event = "session_proposal" | "session_request" | "session_delete" | "auth_request"; + type Event = + | "session_proposal" + | "session_proposal_error" + | "session_request" + | "session_delete" + | "auth_request"; interface BaseEventArgs { id: number; @@ -27,8 +32,14 @@ export declare namespace SingleEthereumTypes { type AuthRequest = Web3WalletTypes.AuthRequest; + type SessionProposalError = { + message: string; + code: number; + }; + interface EventArguments { session_proposal: SessionProposal; + session_proposal_error: SessionProposalError; session_request: SessionRequest; session_delete: SessionDelete; auth_request: AuthRequest; From 04624466f9cbbfbf42eb9b9255f5edeb071293b9 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 24 May 2023 17:58:06 +0300 Subject: [PATCH 3/3] feat: tests --- test/shared/values.ts | 21 ++++++++++++ test/sign.spec.ts | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/test/shared/values.ts b/test/shared/values.ts index eb7258b..4408ac5 100644 --- a/test/shared/values.ts +++ b/test/shared/values.ts @@ -47,6 +47,27 @@ export const TEST_REQUIRED_NAMESPACES = { }, }; +export const TEST_REQUIRED_NAMESPACES_FAIL_CHAINS = { + eip155: { + methods: TEST_METHODS, + chains: [TEST_ETHEREUM_CHAIN, TEST_ARBITRUM_CHAIN], + events: TEST_EVENTS, + }, +}; + +export const TEST_REQUIRED_NAMESPACES_FAIL_NAMESPACES = { + eip155: { + methods: TEST_METHODS, + chains: [TEST_ETHEREUM_CHAIN], + events: TEST_EVENTS, + }, + xyz: { + methods: TEST_METHODS, + chains: ["xyz:1"], + events: TEST_EVENTS, + }, +}; + export const TEST_OPTIONAL_NAMESPACES = { eip155: { methods: TEST_OPTIONAL_METHODS, diff --git a/test/sign.spec.ts b/test/sign.spec.ts index 2ec34cf..3a4e228 100644 --- a/test/sign.spec.ts +++ b/test/sign.spec.ts @@ -19,6 +19,8 @@ import { TEST_NAMESPACES, TEST_OPTIONAL_NAMESPACES, TEST_REQUIRED_NAMESPACES, + TEST_REQUIRED_NAMESPACES_FAIL_CHAINS, + TEST_REQUIRED_NAMESPACES_FAIL_NAMESPACES, TEST_UPDATED_NAMESPACES, } from "./shared"; import { prefixChainWithNamespace } from "../src/utils"; @@ -419,4 +421,78 @@ describe("Sign Integration", () => { }), ]); }); + it("should emit session_proposal_error with failed chains validation", async () => { + const core = new Core(TEST_CORE_OPTIONS); + const dapp = await SignClient.init({ + ...TEST_CORE_OPTIONS, + name: "Dapp", + }); + const { uri, approval } = await dapp.connect({ + requiredNamespaces: TEST_REQUIRED_NAMESPACES_FAIL_CHAINS, + }); + const uriString = uri || ""; + const wallet = await SingleEthereum.init({ + core, + name: "wallet", + metadata: {} as any, + }); + const expectedError = getSdkError("UNSUPPORTED_CHAINS"); + await Promise.all([ + new Promise(async (resolve) => { + wallet.on("session_proposal_error", (sessionProposalError) => { + expect(sessionProposalError).to.be.exist; + expect(sessionProposalError).to.toMatchObject(expectedError); + resolve(); + }); + }), + new Promise(async (resolve) => { + await approval().catch((error) => { + expect(error).to.be.exist; + expect(error).to.toMatchObject(expectedError); + resolve(); + }); + }), + wallet.pair({ uri: uriString }), + ]); + [dapp, wallet].forEach(async (client) => { + await disconnect(client.core); + }); + }); + it("should emit session_proposal_error with failed namespaces validation", async () => { + const core = new Core(TEST_CORE_OPTIONS); + const dapp = await SignClient.init({ + ...TEST_CORE_OPTIONS, + name: "Dapp", + }); + const { uri, approval } = await dapp.connect({ + requiredNamespaces: TEST_REQUIRED_NAMESPACES_FAIL_NAMESPACES, + }); + const uriString = uri || ""; + const wallet = await SingleEthereum.init({ + core, + name: "wallet", + metadata: {} as any, + }); + const expectedError = getSdkError("UNSUPPORTED_NAMESPACE_KEY"); + await Promise.all([ + new Promise(async (resolve) => { + wallet.on("session_proposal_error", (sessionProposalError) => { + expect(sessionProposalError).to.be.exist; + expect(sessionProposalError).to.toMatchObject(expectedError); + resolve(); + }); + }), + new Promise(async (resolve) => { + await approval().catch((error) => { + expect(error).to.be.exist; + expect(error).to.toMatchObject(expectedError); + resolve(); + }); + }), + wallet.pair({ uri: uriString }), + ]); + [dapp, wallet].forEach(async (client) => { + await disconnect(client.core); + }); + }); });