Skip to content
This repository was archived by the owner on Jan 10, 2026. It is now read-only.

Commit 059db27

Browse files
authored
Merge pull request #201 from WalletConnect/fix/unhandled-event-exception
fix: unhandledable session event exception
2 parents 183db5a + dabb1a2 commit 059db27

5 files changed

Lines changed: 12 additions & 2 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<DefaultVersion>2.4.0</DefaultVersion>
4+
<DefaultVersion>2.4.1</DefaultVersion>
55
<DefaultTargetFrameworks>net6.0;net7.0;net8.0;netstandard2.1;</DefaultTargetFrameworks>
66
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
77
</PropertyGroup>

Tests/WalletConnectSharp.Web3Wallet.Tests/SignTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ await Task.WhenAll(
580580

581581
Assert.True(_dapp.TryUnsubscribeFromSessionEvent(referenceTypeEventData.Name, ReferenceTypeEventHandler));
582582
Assert.True(_dapp.TryUnsubscribeFromSessionEvent(valueTypeEventData.Name, ValueTypeEventHandler));
583+
584+
// Test invalid chains
585+
await Assert.ThrowsAsync<FormatException>(() => _wallet.EmitSessionEvent(session.Topic, valueTypeEventData, "invalid chain"));
586+
await Assert.ThrowsAsync<NamespacesException>(() => _wallet.EmitSessionEvent(session.Topic, valueTypeEventData, "123:321"));
583587
}
584588

585589
[Fact, Trait("Category", "unit")]

WalletConnectSharp.Sign/Engine.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using WalletConnectSharp.Common.Model.Errors;
88
using WalletConnectSharp.Common.Model.Relay;
99
using WalletConnectSharp.Common.Utils;
10+
using WalletConnectSharp.Core;
1011
using WalletConnectSharp.Core.Interfaces;
1112
using WalletConnectSharp.Core.Models;
1213
using WalletConnectSharp.Core.Models.Pairing;
@@ -818,6 +819,7 @@ public async Task Respond<T, TR>(string topic, JsonRpcResponse<TR> response)
818819
public async Task Emit<T>(string topic, EventData<T> eventData, string chainId = null)
819820
{
820821
IsInitialized();
822+
await PrivateThis.IsValidEmit(topic, eventData, chainId);
821823
await MessageHandler.SendRequest<SessionEvent<T>, object>(topic,
822824
new SessionEvent<T> { ChainId = chainId, Event = eventData, Topic = topic });
823825
}

WalletConnectSharp.Sign/Internals/EngineHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ async Task IEnginePrivate.OnSessionEventRequest(string topic, JsonRpcRequest<Ses
352352
{
353353
await MessageHandler.SendError<SessionEvent<JToken>, bool>(id, topic, Error.FromException(e));
354354
}
355+
catch (Exception e) // to avoid unhandled exceptions caused by invalid events sent by another peer
356+
{
357+
logger.LogError(e);
358+
}
355359
}
356360
}
357361
}

WalletConnectSharp.Sign/Internals/EngineValidation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ private void ValidateNamespacesChainId(Namespaces namespaces, string chainId)
344344
{
345345
if (!Utils.IsValidChainId(chainId))
346346
{
347-
throw new FormatException($"ChainId {chainId} should be a string and conform to 'chainId:chainId' format.");
347+
throw new FormatException($"ChainId {chainId} should be a string and conform to CAIP-2.");
348348
}
349349

350350
var chains = GetNamespacesChains(namespaces);

0 commit comments

Comments
 (0)