Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow session expiry to be configurable #126

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions WalletConnectSharp.Sign/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ public async Task<ConnectedData> Connect(ConnectOptions options)
var id = await MessageHandler.SendRequest<SessionPropose, SessionProposeResponse>(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()
{
Expand Down
30 changes: 30 additions & 0 deletions WalletConnectSharp.Sign/Models/Engine/ConnectOptions.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,6 +43,13 @@ public class ConnectOptions
[JsonProperty("relays")]
public ProtocolOptions Relays;

/// <summary>
/// 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
/// </summary>
[JsonProperty("expiry")]
public long Expiry = Clock.FIVE_MINUTES;

/// <summary>
/// Create blank options with no required namespaces
/// </summary>
Expand Down Expand Up @@ -156,5 +164,27 @@ public ConnectOptions WithOptions(ProtocolOptions options)
Relays = options;
return this;
}

/// <summary>
/// Set the expiry duration for the session
/// </summary>
/// <param name="seconds">The amount of seconds that should pass before the session expires</param>
/// <returns>This object, acts a builder function</returns>
public ConnectOptions WithExpiry(long seconds)
{
Expiry = seconds;
return this;
}

/// <summary>
/// Set the expiry duration for the session
/// </summary>
/// <param name="expiry">The amount of time that should pass before the session expires</param>
/// <returns>This object, acts a builder function</returns>
public ConnectOptions WithExpiry(TimeSpan expiry)
{
Expiry = (long)expiry.TotalSeconds;
return this;
}
}
}
Loading