Skip to content

Commit

Permalink
Merge pull request #13 from WalletConnect/feat/emit-session-proposal-…
Browse files Browse the repository at this point in the history
…error

feat: emit session proposal error
  • Loading branch information
ganchoradkov authored May 24, 2023
2 parents 5138a9d + 0462446 commit ffdd581
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,23 @@ 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,
});
}

try {
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", {
Expand Down
13 changes: 12 additions & 1 deletion src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = unknown> {
id: number;
Expand All @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions test/shared/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
76 changes: 76 additions & 0 deletions test/sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<void>(async (resolve) => {
wallet.on("session_proposal_error", (sessionProposalError) => {
expect(sessionProposalError).to.be.exist;
expect(sessionProposalError).to.toMatchObject(expectedError);
resolve();
});
}),
new Promise<void>(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<void>(async (resolve) => {
wallet.on("session_proposal_error", (sessionProposalError) => {
expect(sessionProposalError).to.be.exist;
expect(sessionProposalError).to.toMatchObject(expectedError);
resolve();
});
}),
new Promise<void>(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);
});
});
});
86 changes: 70 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,29 @@
events "^3.3.0"
isomorphic-unfetch "^3.1.0"

"@walletconnect/[email protected]", "@walletconnect/core@^2.7.2":
"@walletconnect/[email protected]":
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==
Expand Down Expand Up @@ -980,19 +1002,19 @@
dependencies:
tslib "1.14.1"

"@walletconnect/[email protected].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/[email protected].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":
Expand All @@ -1014,6 +1036,18 @@
"@walletconnect/logger" "^2.0.1"
events "^3.3.0"

"@walletconnect/[email protected]":
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/[email protected]", "@walletconnect/utils@^2.7.2":
version "2.7.6"
resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.7.6.tgz#42ff9d7bb3c1874aa85d480181c6a7aafc34c90f"
Expand All @@ -1034,19 +1068,39 @@
query-string "7.1.3"
uint8arrays "^3.1.0"

"@walletconnect/[email protected]":
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/[email protected]":
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/[email protected]":
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"
Expand Down

2 comments on commit ffdd581

@vercel
Copy link

@vercel vercel bot commented on ffdd581 May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

se-sdk-dapp – ./examples/dapp/

se-sdk-dapp.vercel.app
se-sdk-dapp-git-main-walletconnect1.vercel.app
se-sdk-dapp-walletconnect1.vercel.app

@vercel
Copy link

@vercel vercel bot commented on ffdd581 May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

se-sdk-wallet – ./examples/wallet/

se-sdk-wallet.vercel.app
se-sdk-wallet-walletconnect1.vercel.app
se-sdk-wallet-git-main-walletconnect1.vercel.app

Please sign in to comment.