-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #679 from WalletConnect/feature/sign-session-expiry
[Sign] Session request expiry
- Loading branch information
Showing
14 changed files
with
350 additions
and
34 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
.swiftpm/xcode/xcshareddata/xcschemes/WalletConnectSignTests.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1410" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "WalletConnectSignTests" | ||
BuildableName = "WalletConnectSignTests" | ||
BlueprintName = "WalletConnectSignTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Foundation | ||
|
||
final class HistoryService { | ||
|
||
private let history: RPCHistory | ||
|
||
init(history: RPCHistory) { | ||
self.history = history | ||
} | ||
|
||
func getPendingRequests() -> [Request] { | ||
return history.getPending() | ||
.compactMap { mapRequestRecord($0) } | ||
.filter { !$0.isExpired() } | ||
} | ||
|
||
func getPendingRequests(topic: String) -> [Request] { | ||
return getPendingRequests().filter { $0.topic == topic } | ||
} | ||
|
||
public func getSessionRequest(id: RPCID) -> Request? { | ||
guard let record = history.get(recordId: id) else { return nil } | ||
return mapRequestRecord(record) | ||
} | ||
} | ||
|
||
private extension HistoryService { | ||
|
||
func mapRequestRecord(_ record: RPCHistory.Record) -> Request? { | ||
guard let request = try? record.request.params?.get(SessionType.RequestParams.self) | ||
else { return nil } | ||
|
||
return Request( | ||
id: record.id, | ||
topic: record.topic, | ||
method: request.request.method, | ||
params: request.request.params, | ||
chainId: request.chainId, | ||
expiry: request.request.expiry | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
Sources/WalletConnectSign/Types/ProtocolMethods/SessionRequestProtocolMethod.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
import Foundation | ||
|
||
struct SessionRequestProtocolMethod: ProtocolMethod { | ||
|
||
static let defaultTtl: Int = 300 | ||
|
||
let method: String = "wc_sessionRequest" | ||
|
||
let requestConfig = RelayConfig(tag: 1108, prompt: true, ttl: 300) | ||
private let ttl: Int | ||
|
||
var requestConfig: RelayConfig { | ||
RelayConfig(tag: 1108, prompt: true, ttl: ttl) | ||
} | ||
|
||
var responseConfig: RelayConfig { | ||
RelayConfig(tag: 1109, prompt: false, ttl: ttl) | ||
} | ||
|
||
let responseConfig = RelayConfig(tag: 1109, prompt: false, ttl: 300) | ||
init(ttl: Int = Self.defaultTtl) { | ||
self.ttl = ttl | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.