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-4001] Update PreAuthorization models #1400

Merged
merged 6 commits into from
Nov 29, 2024

Conversation

matiasbzurovski
Copy link
Contributor

@matiasbzurovski matiasbzurovski commented Nov 28, 2024

Jira ticket: ABW-4001

Description

Updates response to include SubintentHash and expirationTimestamp, which allows us to remove the PreAuthData helper struct we moved along DappInteractor (and children).

How to test

Play with Anthic test app and verify everything works as expected.

var timestamp: Date {
switch self {
case let .afterDelay(afterDelay):
Date().addingTimeInterval(TimeInterval(afterDelay.expireAfterSeconds))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date()? Shouldn't the timestamp be UTC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh dearful dates and timezones.. Let me write down my dummy/cautious reasoning to validate the current logic makes sense.

In this case, the subintent will expire X seconds after signature. Let's use 600 (10 minutes) for this example, which we will set using the test dApp.

It is currently 13:54 PM GMT+1 in Madrid. This means that when I get to this state, the timestamp: Date will return 14:04 GMT+1.

Given this timestamp is used on the PollPreAuthorizationStatus+View, we can validate that after signing the preAuth, the view says that it expires in 9 minutes (it shows 10 minutes only for a second) and not in -50 minutes (as it would be in GMT timezone)

So far so good, now we need to make sure that the value sent to Sargon and then to the dApp makes sense. The process here is:

  • convert Swift.Date into Sargon.Timestamp (happens thanks to magic code in uniffi.toml)
  • get amount of second since this timestamp and send it to dApp (done here)

Now, if we check the final result sent to the dApp we can see it is 1732799073.
Screenshot 2024-11-28 at 13 58 36

Then, using a Playground I can confirm this value corresponds to 14:04 in my timezone:
Screenshot 2024-11-28 at 14 00 09

Or if I use a helper tool such as https://www.unixtimestamp.com/ we can verify it is 14:04 GMT+1 and 13:04 GMT:

Copy link
Contributor

@GhenadieVP GhenadieVP Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that the same delay applies, regardless of the base, I think this could be safe, unless user goes and changes the date in the settings while the countdown is ticking 😄.

But as we have discussed, the same timestamp that is calculated when creating the Subintent should be used in all places.

@matiasbzurovski matiasbzurovski force-pushed the ABW-4001-update-pre-auth-models branch from 44bc768 to beae529 Compare November 29, 2024 10:52
@matiasbzurovski matiasbzurovski merged commit 825a116 into main Nov 29, 2024
6 checks passed
@matiasbzurovski matiasbzurovski deleted the ABW-4001-update-pre-auth-models branch November 29, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants