diff --git a/WalletConnectSharp.Sign/Engine.cs b/WalletConnectSharp.Sign/Engine.cs index de57db1..1f6f671 100644 --- a/WalletConnectSharp.Sign/Engine.cs +++ b/WalletConnectSharp.Sign/Engine.cs @@ -97,6 +97,7 @@ private void WrapPairingEvents() { this.Client.Core.Pairing.PairingPinged += (sender, @event) => this.PairingPinged?.Invoke(sender, @event); this.Client.Core.Pairing.PairingDeleted += (sender, @event) => this.PairingDeleted?.Invoke(sender, @event); + this.Client.Core.Pairing.PairingExpired += (sender, @event) => this.PairingExpired?.Invoke(sender, @event); } private void RegisterExpirerEvents() @@ -114,21 +115,97 @@ private void RegisterRelayerEvents() MessageHandler.HandleMessageType(PrivateThis.OnSessionDeleteRequest, null); MessageHandler.HandleMessageType(PrivateThis.OnSessionPingRequest, PrivateThis.OnSessionPingResponse); } - + + /// + /// This event is invoked when the given session has expired + /// Event Side: dApp & Wallet + /// public event EventHandler SessionExpired; - public event EventHandler PairingExpired; + + /// + /// This event is invoked when the given pairing has expired + /// Event Side: Wallet + /// + public event EventHandler PairingExpired; + + /// + /// This event is invoked when a new session is proposed. This is usually invoked + /// after a new pairing has been activated from a URI + /// Event Side: Wallet + /// public event EventHandler SessionProposed; + + /// + /// This event is invoked when a proposed session has been connected to a wallet. This event is + /// triggered after the session has been approved by a wallet + /// Event Side: dApp + /// public event EventHandler SessionConnected; + + /// + /// This event is invoked when a proposed session connection failed with an error + /// Event Side: dApp + /// public event EventHandler SessionConnectionErrored; + + /// + /// This event is invoked when a given session sent a update request. + /// Event Side: Wallet + /// public event EventHandler SessionUpdateRequest; + + /// + /// This event is invoked when a given session sent a extend request. + /// Event Side: Wallet + /// public event EventHandler SessionExtendRequest; + + /// + /// This event is invoked when a given session update request was successful. + /// Event Side: dApp + /// public event EventHandler SessionUpdated; + + /// + /// This event is invoked when a given session extend request was successful. + /// Event Side: dApp + /// public event EventHandler SessionExtended; + + /// + /// This event is invoked when a given session has been pinged + /// Event Side: dApp & Wallet + /// public event EventHandler SessionPinged; + + /// + /// This event is invoked whenever a session has been deleted + /// Event Side: dApp & Wallet + /// public event EventHandler SessionDeleted; + + /// + /// This event is invoked whenever a session has been rejected + /// Event Side: Wallet + /// public event EventHandler SessionRejected; + + /// + /// This event is invoked whenever a session has been approved + /// Event Side: Wallet + /// public event EventHandler SessionApproved; + + /// + /// This event is invoked whenever a pairing is pinged + /// Event Side: dApp & Wallet + /// public event EventHandler PairingPinged; + + /// + /// This event is invoked whenever a pairing is deleted + /// Event Side: dApp & Wallet + /// public event EventHandler PairingDeleted; /// @@ -705,13 +782,18 @@ public async Task Disconnect(string topic, Error reason) if (this.Client.Session.Keys.Contains(topic)) { - await MessageHandler.SendRequest(topic, new SessionDelete() + var id = await MessageHandler.SendRequest(topic, new SessionDelete() { Code = error.Code, Message = error.Message, Data = error.Data }); await PrivateThis.DeleteSession(topic); + this.SessionDeleted?.Invoke(this, new SessionEvent() + { + Topic = topic, + Id = id + }); } else if (this.Client.Core.Pairing.Store.Keys.Contains(topic)) { diff --git a/WalletConnectSharp.Sign/Interfaces/IEngineAPI.cs b/WalletConnectSharp.Sign/Interfaces/IEngineAPI.cs index b544125..8a4b442 100644 --- a/WalletConnectSharp.Sign/Interfaces/IEngineAPI.cs +++ b/WalletConnectSharp.Sign/Interfaces/IEngineAPI.cs @@ -14,34 +14,96 @@ namespace WalletConnectSharp.Sign.Interfaces /// public interface IEngineAPI { + /// + /// This event is invoked when the given session has expired + /// Event Side: dApp & Wallet + /// event EventHandler SessionExpired; - event EventHandler PairingExpired; + /// + /// This event is invoked when the given pairing has expired + /// Event Side: Wallet + /// + event EventHandler PairingExpired; + /// + /// This event is invoked when a new session is proposed. This is usually invoked + /// after a new pairing has been activated from a URI + /// Event Side: Wallet + /// event EventHandler SessionProposed; + /// + /// This event is invoked when a proposed session has been connected to a wallet. This event is + /// triggered after the session has been approved by a wallet + /// Event Side: dApp + /// event EventHandler SessionConnected; + /// + /// This event is invoked when a proposed session connection failed with an error + /// Event Side: dApp + /// event EventHandler SessionConnectionErrored; + /// + /// This event is invoked when a given session sent a update request. + /// Event Side: Wallet + /// event EventHandler SessionUpdateRequest; + /// + /// This event is invoked when a given session sent a extend request. + /// Event Side: Wallet + /// event EventHandler SessionExtendRequest; + /// + /// This event is invoked when a given session update request was successful. + /// Event Side: dApp + /// event EventHandler SessionUpdated; + /// + /// This event is invoked when a given session extend request was successful. + /// Event Side: dApp + /// event EventHandler SessionExtended; + /// + /// This event is invoked when a given session has been pinged + /// Event Side: dApp & Wallet + /// event EventHandler SessionPinged; + /// + /// This event is invoked whenever a session has been deleted + /// Event Side: dApp & Wallet + /// event EventHandler SessionDeleted; + /// + /// This event is invoked whenever a session has been rejected + /// Event Side: Wallet + /// event EventHandler SessionRejected; + /// + /// This event is invoked whenever a session has been approved + /// Event Side: Wallet + /// event EventHandler SessionApproved; + /// + /// This event is invoked whenever a pairing is pinged + /// Event Side: dApp & Wallet + /// event EventHandler PairingPinged; + /// + /// This event is invoked whenever a pairing is deleted + /// Event Side: dApp & Wallet + /// event EventHandler PairingDeleted; /// diff --git a/WalletConnectSharp.Sign/Internals/EngineHandler.cs b/WalletConnectSharp.Sign/Internals/EngineHandler.cs index f06fee2..1d1ae98 100644 --- a/WalletConnectSharp.Sign/Internals/EngineHandler.cs +++ b/WalletConnectSharp.Sign/Internals/EngineHandler.cs @@ -35,6 +35,10 @@ await PrivateThis.DeletePendingSessionRequest((long)target.Id, var session = this.Client.Session.Get(topic); await PrivateThis.DeleteSession(topic); this.SessionExpired?.Invoke(this, session); + this.SessionDeleted?.Invoke(this, new SessionEvent() + { + Topic = topic + }); } else if (target.Id != null) { diff --git a/WalletConnectSharp.Sign/Internals/EngineValidation.cs b/WalletConnectSharp.Sign/Internals/EngineValidation.cs index 0a19a81..9657561 100644 --- a/WalletConnectSharp.Sign/Internals/EngineValidation.cs +++ b/WalletConnectSharp.Sign/Internals/EngineValidation.cs @@ -51,7 +51,7 @@ async Task IsValidPairingTopic(string topic) } } - async Task IsValidSessionTopic(string topic) + Task IsValidSessionTopic(string topic) { if (string.IsNullOrWhiteSpace(topic)) throw WalletConnectException.FromType(ErrorType.MISSING_OR_INVALID, @@ -64,9 +64,11 @@ async Task IsValidSessionTopic(string topic) var expiry = this.Client.Session.Get(topic).Expiry; if (expiry != null && Clock.IsExpired(expiry.Value)) { - await PrivateThis.DeleteSession(topic); + //await PrivateThis.DeleteSession(topic); throw WalletConnectException.FromType(ErrorType.EXPIRED, $"session topic: {topic}"); } + + return Task.CompletedTask; } async Task IsValidProposalId(long id) diff --git a/WalletConnectSharp.Sign/WalletConnectSignClient.cs b/WalletConnectSharp.Sign/WalletConnectSignClient.cs index 9a57fc8..a1a788f 100644 --- a/WalletConnectSharp.Sign/WalletConnectSignClient.cs +++ b/WalletConnectSharp.Sign/WalletConnectSignClient.cs @@ -115,7 +115,7 @@ public int Version public event EventHandler SessionExpired; - public event EventHandler PairingExpired; + public event EventHandler PairingExpired; public event EventHandler SessionProposed; public event EventHandler SessionConnected; public event EventHandler SessionConnectionErrored; @@ -226,6 +226,8 @@ private void WrapEngineEvents() Engine.SessionApproved += (sender, @struct) => this.SessionApproved?.Invoke(sender, @struct); Engine.SessionExtended += (sender, @event) => this.SessionExtended?.Invoke(sender, @event); Engine.SessionUpdated += (sender, @event) => this.SessionUpdated?.Invoke(sender, @event); + Engine.PairingDeleted += (sender, @event) => this.PairingDeleted?.Invoke(sender, @event); + Engine.PairingPinged += (sender, @event) => this.PairingPinged?.Invoke(sender, @event); } ///