From 4e0726f25d7b6763680d5345324bc26799e07a1f Mon Sep 17 00:00:00 2001 From: Julia Seward Date: Wed, 4 Oct 2023 17:06:53 -0400 Subject: [PATCH 1/3] feat: allow session expiry to be configurable --- WalletConnectSharp.Sign/Engine.cs | 4 ++-- WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/WalletConnectSharp.Sign/Engine.cs b/WalletConnectSharp.Sign/Engine.cs index 99bdee4..e301f12 100644 --- a/WalletConnectSharp.Sign/Engine.cs +++ b/WalletConnectSharp.Sign/Engine.cs @@ -306,8 +306,8 @@ public async Task Connect(ConnectOptions options) var id = await MessageHandler.SendRequest(topic, proposal); logger.Log($"Got back {id} as request pending id"); - - var expiry = Clock.CalculateExpiry(Clock.FIVE_MINUTES); + + var expiry = Clock.CalculateExpiry(options.Expiry); await PrivateThis.SetProposal(id, new ProposalStruct() { diff --git a/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs b/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs index cd8ad59..c37539d 100644 --- a/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs +++ b/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using WalletConnectSharp.Common.Model.Relay; +using WalletConnectSharp.Common.Utils; using WalletConnectSharp.Core.Models.Relay; namespace WalletConnectSharp.Sign.Models.Engine @@ -42,6 +43,13 @@ public class ConnectOptions [JsonProperty("relays")] public ProtocolOptions Relays; + /// + /// How long the session will be open before it's considered expired. If the session + /// is expired, then Extend must be called on the session to extend the expiry + /// + [JsonProperty("expiry")] + public long Expiry = Clock.FIVE_MINUTES; + /// /// Create blank options with no required namespaces /// From 492c4db1f080a9ad6a820dd1f3236b208a1a9d0a Mon Sep 17 00:00:00 2001 From: Julia Seward Date: Wed, 4 Oct 2023 17:09:38 -0400 Subject: [PATCH 2/3] feat: add helper functions in connectoptions for expiry --- .../Models/Engine/ConnectOptions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs b/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs index c37539d..c6806f6 100644 --- a/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs +++ b/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs @@ -164,5 +164,17 @@ public ConnectOptions WithOptions(ProtocolOptions options) Relays = options; return this; } + + public ConnectOptions WithExpiry(long seconds) + { + Expiry = seconds; + return this; + } + + public ConnectOptions WithExpiry(TimeSpan expiry) + { + Expiry = (long)expiry.TotalSeconds; + return this; + } } } From c8d1afa60b4f392e887d1d9517b24322348962f6 Mon Sep 17 00:00:00 2001 From: Julia Seward Date: Wed, 4 Oct 2023 17:11:33 -0400 Subject: [PATCH 3/3] chore: docs --- .../Models/Engine/ConnectOptions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs b/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs index c6806f6..dcf6d48 100644 --- a/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs +++ b/WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs @@ -165,12 +165,22 @@ public ConnectOptions WithOptions(ProtocolOptions options) return this; } + /// + /// Set the expiry duration for the session + /// + /// The amount of seconds that should pass before the session expires + /// This object, acts a builder function public ConnectOptions WithExpiry(long seconds) { Expiry = seconds; return this; } + /// + /// Set the expiry duration for the session + /// + /// The amount of time that should pass before the session expires + /// This object, acts a builder function public ConnectOptions WithExpiry(TimeSpan expiry) { Expiry = (long)expiry.TotalSeconds;