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

[ABW-3913] Pre validate the expiration of PreAuthorization requests #1380

Merged
merged 3 commits into from
Nov 11, 2024
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
11 changes: 1 addition & 10 deletions RadixWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9178,14 +9178,6 @@
version = 6.13.2;
};
};
5B3047A72CD26EB1009FAF90 /* XCRemoteSwiftPackageReference "sargon" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/radixdlt/sargon/";
requirement = {
kind = exactVersion;
version = 1.1.44;
};
};
5B634A922C91D2A0004B2FBC /* XCRemoteSwiftPackageReference "ScreenshotPreventing-iOS" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Sajjon/ScreenshotPreventing-iOS";
Expand All @@ -9207,7 +9199,7 @@
repositoryURL = "https://github.com/radixdlt/sargon";
requirement = {
kind = exactVersion;
version = 1.1.47;
version = 1.1.48;
};
};
A415574E2B757C5E0040AD4E /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = {
Expand Down Expand Up @@ -9431,7 +9423,6 @@
};
5B4E1D1E2CB7FE8E002FAC2E /* Sargon */ = {
isa = XCSwiftPackageProductDependency;
package = 5B4E1D1D2CB7FE8E002FAC2E /* XCRemoteSwiftPackageReference "sargon" */;
productName = Sargon;
};
5B634A932C91D2A0004B2FBC /* ScreenshotPreventing */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/radixdlt/sargon",
"state" : {
"revision" : "95c81df01619eac9923ad0211de74428764659da",
"version" : "1.1.47"
"revision" : "a8f7bba9d7ae58ab0cf21ef47e0d87e59d7f3198",
"version" : "1.1.48"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ extension DappInteractionClient {
case dAppValidationError(String)
case badContent(BadContent)
case invalidPersonaOrAccounts
case invalidPreAuthorization(InvalidPreAuthorization)

enum BadContent: Sendable, Hashable {
case numberOfAccountsInvalid
}

enum InvalidPreAuthorization: Sendable, Hashable {
case expirationTooClose
case expired
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ extension DappInteractionClient {
return invalidRequest(.invalidPersonaOrAccounts)
}

case let .preAuthorization(preAuthorization):
switch preAuthorization.request.expiration.getStatus() {
case .valid:
break
case .expirationTooClose:
return invalidRequest(.invalidPreAuthorization(.expirationTooClose))
case .expired:
return invalidRequest(.invalidPreAuthorization(.expired))
}

default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ extension DappInteractionClient.ValidatedDappRequest.InvalidRequestReason {
.invalidRequest
case .invalidPersonaOrAccounts:
.invalidPersonaOrAccounts
case .invalidPreAuthorization(.expirationTooClose):
.subintentExpirationTooClose
case .invalidPreAuthorization(.expired):
.expiredSubintent
}
}

Expand All @@ -406,10 +410,8 @@ extension DappInteractionClient.ValidatedDappRequest.InvalidRequestReason {
L10n.DAppRequest.ValidationOutcome.subtitleIncompatibleVersion
case .wrongNetworkID:
L10n.DAppRequest.ValidationOutcome.subtitleWrongNetworkID
case .invalidOrigin, .invalidDappDefinitionAddress, .dAppValidationError:
case .invalidOrigin, .invalidDappDefinitionAddress, .dAppValidationError, .invalidPersonaOrAccounts, .invalidPreAuthorization:
shortExplanation
case .invalidPersonaOrAccounts:
L10n.DAppRequest.ValidationOutcome.invalidPersonaOrAccoubts
}
}

Expand All @@ -436,7 +438,7 @@ extension DappInteractionClient.ValidatedDappRequest.InvalidRequestReason {
L10n.DAppRequest.ValidationOutcome.devExplanationInvalidDappDefinitionAddress(invalidAddress)
case let .dAppValidationError(underlyingError):
"\(L10n.DAppRequest.ValidationOutcome.invalidRequestMessage): \(underlyingError)"
case .wrongNetworkID, .invalidPersonaOrAccounts:
case .wrongNetworkID, .invalidPersonaOrAccounts, .invalidPreAuthorization:
shortExplanation
}
}
Expand All @@ -461,6 +463,10 @@ extension DappInteractionClient.ValidatedDappRequest.InvalidRequestReason {
L10n.DAppRequest.RequestWrongNetworkAlert.message(networkName(for: ce), networkName(for: wallet))
case .invalidPersonaOrAccounts:
L10n.DAppRequest.ValidationOutcome.invalidPersonaOrAccoubts
case .invalidPreAuthorization(.expirationTooClose):
L10n.DAppRequest.ValidationOutcome.preAuthorizationExpirationTooClose
case .invalidPreAuthorization(.expired):
L10n.DAppRequest.ValidationOutcome.preAuthorizationExpired
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct PreAuthorizationReview: Sendable, FeatureReducer {
switch state.expiration {
case let .atTime(value):
// Trigger expiration countdown effect
let expirationDate = value.unixTimestampSeconds
let expirationDate = value.date
state.secondsToExpiration = Int(expirationDate.timeIntervalSinceNow)
effects.append(startTimer(expirationDate: expirationDate))
case .afterDelay:
Expand Down Expand Up @@ -269,7 +269,7 @@ extension PreAuthorizationReview.State {
var isExpired: Bool {
switch expiration {
case let .atTime(value):
value.unixTimestampSeconds <= Date.now
value.date <= Date.now
case .afterDelay:
false
}
Expand Down
Loading